<commit_before>$(function() {
  var masterURL = "https://download.go.cd/";

  if ($('#show-checksum').length === 0) {
    return;
  }

  $('#show-checksum').change(function(evt) {
    var input = $(evt.target);

    if (input.is(':checked')) {
      $('.checksums').show();
    } else {
      $('.checksums').hide();
    }
  });

  $(document).ready(init);

  function init() {
    fetchArtifacts(function(artifactList) {
      renderInstallersByOS(artifactList, "mac", 'mac-revisions');
      renderInstallersByOS(artifactList, "solaris", 'solaris-revisions');
      renderInstallersByOS(artifactList, "linuxDeb", 'linuxDeb-revisions');
      renderInstallersByOS(artifactList, "linuxRpm", 'linuxRpm-revisions');
      renderInstallersByOS(artifactList, "package", 'package-revisions');
      renderInstallersByOS(artifactList, "win", 'windows-revisions');
      setupJourneyTracker(artifactList);
    });
  }

  function hideLoader() {
    $('#download-loader').remove();
  }

  function GTMID(artifact, file) {
    var splitArtifactType = file.type.split("-");
    return splitArtifactType[0].charAt(0).toUpperCase() + splitArtifactType[0].slice(1) + '-' + splitArtifactType[1].charAt(0).toUpperCase() + splitArtifactType[1].slice(1) + "_" + artifact.version;
  }

  function downloadType(file) {
    if (file.name.indexOf("server") > 0) {
      return "Server";
    } else if (file.name.indexOf("agent") > 0) {
      return "Agent";
    }
  }


  function setupJourneyTracker(artifactList) {
    if (typeof jtr === "undefined") {
      return;
    }
    _.each(artifactList, function(artifact) {
      _.each(artifact.files, function(file) {
        var type = downloadType(file);
        if (!type) {
          return;
        }
        var linkSelector = '#' + GTMID(artifact, file).replace(/\./g, "\\.");
        $(linkSelector).click(function() {
          try {
            jtr.track(type.toLowerCase() + " download", {
              download_release_type: artifact.release_type,
              download_version: artifact.version,
              download_file_type: file.type,
              download_file_name: file.name
            });
          } catch (e) {
            //ignore
          }
        });
      });
    });
  }

  function fetchArtifacts(callbackFn) {
    var originalRender = function(ArtifactList) {
      var supported = _.chain(ArtifactList).where({
        release_type: "supported"
      }).reject(function(artifact) {
        return artifact.hidden == true;
      }).value();
      var unsupported = _.chain(ArtifactList).reject({
        release_type: "supported"
      }).reject(function(artifact) {
        return artifact.hidden == true;
      }).value().reverse();
      callbackFn(supported.concat(unsupported));
      hideLoader();
    };

    if (document.location.search === '?new') {
      var releases = [];

      var render = _.after(2, function() {
        releases = _.compact(releases);

        releases = _.chain(releases).sortBy(function(release) {
          return (release.release_type + "_" + release.version);
        }).reverse().value();
<commit_msg>Sort out the sorting and reversing mess.<commit_after>$(function() {
  var masterURL = "https://download.go.cd/";

  if ($('#show-checksum').length === 0) {
    return;
  }

  $('#show-checksum').change(function(evt) {
    var input = $(evt.target);

    if (input.is(':checked')) {
      $('.checksums').show();
    } else {
      $('.checksums').hide();
    }
  });

  $(document).ready(init);

  function init() {
    fetchArtifacts(function(artifactList) {
      renderInstallersByOS(artifactList, "mac", 'mac-revisions');
      renderInstallersByOS(artifactList, "solaris", 'solaris-revisions');
      renderInstallersByOS(artifactList, "linuxDeb", 'linuxDeb-revisions');
      renderInstallersByOS(artifactList, "linuxRpm", 'linuxRpm-revisions');
      renderInstallersByOS(artifactList, "package", 'package-revisions');
      renderInstallersByOS(artifactList, "win", 'windows-revisions');
      setupJourneyTracker(artifactList);
    });
  }

  function hideLoader() {
    $('#download-loader').remove();
  }

  function GTMID(artifact, file) {
    var splitArtifactType = file.type.split("-");
    return splitArtifactType[0].charAt(0).toUpperCase() + splitArtifactType[0].slice(1) + '-' + splitArtifactType[1].charAt(0).toUpperCase() + splitArtifactType[1].slice(1) + "_" + artifact.version;
  }

  function downloadType(file) {
    if (file.name.indexOf("server") > 0) {
      return "Server";
    } else if (file.name.indexOf("agent") > 0) {
      return "Agent";
    }
  }


  function setupJourneyTracker(artifactList) {
    if (typeof jtr === "undefined") {
      return;
    }
    _.each(artifactList, function(artifact) {
      _.each(artifact.files, function(file) {
        var type = downloadType(file);
        if (!type) {
          return;
        }
        var linkSelector = '#' + GTMID(artifact, file).replace(/\./g, "\\.");
        $(linkSelector).click(function() {
          try {
            jtr.track(type.toLowerCase() + " download", {
              download_release_type: artifact.release_type,
              download_version: artifact.version,
              download_file_type: file.type,
              download_file_name: file.name
            });
          } catch (e) {
            //ignore
          }
        });
      });
    });
  }

  function fetchArtifacts(callbackFn) {
    var originalRender = function(releases) {

      var supported = _.chain(releases).where({
        release_type: "supported"
      }).reject(function(release) {
        return release.hidden == true;
      }).sortBy(function(release){
        return release.version;
      }).reverse().value();

      var unsupported = _.chain(releases).reject({
        release_type: "supported"
      }).reject(function(release) {
        return release.hidden == true;
      }).sortBy(function(release){
        return release.version;
      }).reverse().value();

      callbackFn(supported.concat(unsupported));
      hideLoader();
    };

    if (document.location.search === '?new') {
      var releases = [];

      var render = _.after(2, function() {
        releases = _.compact(releases);
{'fraction_non_alphanumeric': 0.16186181349653728, 'fraction_numerical': 0.0038653567402158156, 'mean_word_length': 2.72079089275015, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5166065', 'n_tokens_mistral': 1933, 'n_tokens_neox': 1832, 'n_words': 302}