<commit_before>
<script>
  $(function () { 
    $("[data-toggle='tooltip']").tooltip(); 
    $("#scoresTable").tablesorter();
  });

  // Function to sort the columns based on the total review score
  function col_sort(m, lesser) {

    // Swaps two columns of the table
    jQuery.moveColumn = function(table, from, to) {
      var rows = jQuery('tr', table);
      var cols;
      rows.each(function() {
        cols = jQuery(this).children('th, td');
        cols.eq(from).detach().insertBefore(cols.eq(to));
        if (from - to > 1) {
          cols.eq(to).detach().insertAfter((cols.eq(from - 1)));

        }
      });
    }

    // Gets all the table with the class "tbl_heat"
    var tables = $("table.tbl_heat");
    // Get all the rows with the class accordion-toggle
    var tbr = tables.eq(m).find('tr.accordion-toggle');
    // Get the cells from the last row of the table
    var columns = tbr.eq(tbr.length - 1).find('td');
    // Init an array to hold the review total
    var sum_array = [];
    // iterate through the rows and calculate the total of each review
    for (var l = 2; l < columns.length - 2; l++) {
      var total = 0;
      for (var n = 0; n < tbr.length; n++) {
        var row_slice = tbr.eq(n).find('td');
        if (parseInt(row_slice[l].innerHTML) > 0) {
          total = total + parseInt(row_slice[l].innerHTML)
        }
      }
      sum_array.push(total)
    }

    // The sorting algorithm
    for (var i = 3; i < columns.length - 2; i++) {
      for (var j = 3; j < columns.length - 2; j++) {
        var k = j - 1
        if (compare(sum_array[j - 2], sum_array[k - 2], lesser)) {
          var tmp
          tmp = sum_array[j - 2]
          sum_array[j - 2] = sum_array[k - 2]
          sum_array[k - 2] = tmp
          jQuery.moveColumn($("table.tbl_heat").eq(m), j, k);
          // This part is repeated since the table is updated
          tables = $("table.tbl_heat")
          tbr = tables.eq(m).find('tr.accordion-toggle');
          columns = tbr.eq(tbr.length - 1).find('td')
        }
      }
    }
  }

  // Function to return boolean based on lesser or greater operator
  function compare(a, b, less) {
    if(less) {
      return a < b
    } else {<commit_msg>Improved algorithm to sort columns<commit_after>
<script>
  $(function () { 
    $("[data-toggle='tooltip']").tooltip(); 
    $("#scoresTable").tablesorter();
  });

  // Function to sort the columns based on the total review score
  function col_sort(m, lesser) {

    // Swaps two columns of the table
    jQuery.moveColumn = function(table, from, to) {
      var rows = jQuery('tr', table);
      var cols;
      rows.each(function() {
        cols = jQuery(this).children('th, td');
        cols.eq(from).detach().insertBefore(cols.eq(to));
        if (from - to > 1) {
          cols.eq(to).detach().insertAfter((cols.eq(from - 1)));

        }
      });
    }

    // Gets all the table with the class "tbl_heat"
    var tables = $("table.tbl_heat");
    // Get all the rows with the class accordion-toggle
    var tbr = tables.eq(m).find('tr.accordion-toggle');
    // Get the cells from the last row of the table
    var columns = tbr.eq(tbr.length - 1).find('td');
    // Init an array to hold the review total
    var sum_array = [];
    // iterate through the rows and calculate the total of each review
    for (var l = 2; l < columns.length - 2; l++) {
      var total = 0;
      for (var n = 0; n < tbr.length; n++) {
        var row_slice = tbr.eq(n).find('td');
        if (parseInt(row_slice[l].innerHTML) > 0) {
          total = total + parseInt(row_slice[l].innerHTML)
        }
      }
      sum_array.push(total)
    }

    // The sorting algorithm
    for (var i = 3; i < columns.length - 2; i++)
    {
      var j=i;
      while(j>2 && compare(sum_array[j - 2], sum_array[j - 3], lesser))
      {
        var tmp
        tmp = sum_array[j - 3]
        sum_array[j - 3] = sum_array[j-2]
        sum_array[j-2] = tmp
        jQuery.moveColumn($("table.tbl_heat").eq(m), j, j-1);
        // This part is repeated since the table is updated
        tables = $("table.tbl_heat")
        tbr = tables.eq(m).find('tr.accordion-toggle');
        columns = tbr.eq(tbr.length - 1).find('td')
        j=j-1	;

      }
    }
  }

  // Function to return boolean based on lesser or greater operator
  function compare(a, b, less) {
    if(less) {
      return a < b
    } else {
{'fraction_non_alphanumeric': 0.15159755268524813, 'fraction_numerical': 0.009064128710627692, 'mean_word_length': 2.0932025227750524, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '955151', 'n_tokens_mistral': 1500, 'n_tokens_neox': 1430, 'n_words': 413}