<commit_before>window.onload = function() {
  var linkedName = window.location.hash.split('#')[1];

  var visUrl = "https://openaustin.cartodb.com/u/oa-admin/api/v2/viz/cb394812-8b56-11e5-91c0-0ecd1babdde5/viz.json"
  var toggleLayers = {};

  cartodb.createVis(map, visUrl)
    .on('done', function(vis, layers) {
      for (var i = 0, len = layers[1].layers.length; i < len; i++) {
        layer = layers[1].layers[i];
        toggleLayers[layer.layer_name] = layer;

        var element = $('<a>')
          .attr('id', layer.layer_name)
          .attr('href', '#' + layer.layer_name)
          .addClass('button')
          .addClass(layer.layer_name)
          .text(layer.layer_name)
          .click(function (event) {
            var clickedName = event.target.id;
            setLayer(clickedName);
          });
        $('#menu').prepend(element);

        if (linkedName !== '' && toggleLayers.hasOwnProperty(linkedName)) {
          setLayer(linkedName);
        } else if (i === 0) {
          setLayer(layer.layer_name);
        }
      };
    });

  function setLayer(layerName) {
    Object.keys(toggleLayers).forEach(function(key) {
      toggleLayers[key].sub.hide();
    })

    toggleLayers[layerName].sub.show();

    $('.button').removeClass('selected');
    $('#' + layerName).addClass('selected');
  }
}<commit_msg>cln: use consistent looping, and avoid leaking global layer var<commit_after>window.onload = function() {
  var linkedName = window.location.hash.split('#')[1];

  var visUrl = "https://openaustin.cartodb.com/u/oa-admin/api/v2/viz/cb394812-8b56-11e5-91c0-0ecd1babdde5/viz.json"
  var toggleLayers = {};

  cartodb.createVis(map, visUrl)
    .on('done', function(vis, layers) {
      for (var i = 0, len = layers[1].layers.length; i < len; i++) {
        var layer = layers[1].layers[i];
        toggleLayers[layer.layer_name] = layer;

        var element = $('<a>')
          .attr('id', layer.layer_name)
          .attr('href', '#' + layer.layer_name)
          .addClass('button')
          .addClass(layer.layer_name)
          .text(layer.layer_name)
          .click(function (event) {
            var clickedName = event.target.id;
            setLayer(clickedName);
          });
        $('#menu').prepend(element);

        if (linkedName !== '' && toggleLayers.hasOwnProperty(linkedName)) {
          setLayer(linkedName);
        } else if (i === 0) {
          setLayer(layer.layer_name);
        }
      };
    });

  function setLayer(layerName) {
    var keys = Object.keys(toggleLayers);
    for (var i = 0, len = keys.length; i < len; i++) {
      var key = keys[i];
      toggleLayers[key].sub.hide();
    }

    toggleLayers[layerName].sub.show();

    $('.button').removeClass('selected');
    $('#' + layerName).addClass('selected');
  }
}
{'fraction_non_alphanumeric': 0.17338565822333216, 'fraction_numerical': 0.017481270067784518, 'mean_word_length': 2.487562189054726, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '5854576', 'n_tokens_mistral': 970, 'n_tokens_neox': 926, 'n_words': 146}