<commit_before>(function() {
  'use strict';

  window._ = {};

  // Returns whatever value is passed as the argument. T
  _.identity = function(val) {
    return val;
  };

  /**
   * COLLECTIONS
   * ===========
   */

  // Return an array of the first n elements of an array. If n is undefined,
  // return just the first element.
  _.first = function(array, n) {
    return n === undefined ? array[0] : array.slice(0, n);
  };

  // Like first, but for the last elements. If n is undefined, return just the
  // last element.
  _.last = function(array, n) {
    if (n > array.length) {
    return array;
  }
    else { 
      return n === undefined ? array[array.length - 1] : array.slice(array.length - n);
    }
  };

  // Call iterator(value, key, collection) for each element of collection.
  // Accepts both arrays and objects.
  //
  // Note: _.each does not have a return value, but rather simply runs the
  // iterator function over each item in the input collection.
  _.each = function(collection, iterator) {
     if(Array.isArray(collection) === true){
         for (var i =0; i < collection.length; i++) {
         iterator(collection[i], i, collection);
         }
      } 
      else {
        for(var key in collection){
        iterator(collection[key], key, collection);
        }
      }
  };

  // Returns the index at which value can be found in the array, or -1 if value
  // is not present in the array.
  _.indexOf = function(array, target){
    var result = -1;

    _.each(array, function(item, index) {
      if (item === target && result === -1) {
        result = index;
      }
    });

    return result;
  };

  // Return all elements of an array that pass a truth test.
  _.filter = function(collection, test) {
    var results = [];
    _.each(collection, function (item){
      if (test(item)) {
        results.push(item)
      }
    })
    return results;
  };

  // Return all elements of an array that don't pass a truth test.
  _.reject = function(collection, test) {
    // We can re-use filter here - look for every element that fails a truth test
    return _.filter(collection, function (item){return !test(item)});
   
  };

  // Produce a duplicate-free version of the array.
  _.uniq = function(array) {
    var uniqueArray = [];
    var trackerObj = {}; //use a tracker object to remember what we have seen in the array previously.
    for (var i = 0; i < array.length; i ++) {
      trackerObj[array[i]] = array[i]
    };
    for (var key in trackerObj) {
      uniqueArray.push(trackerObj[key])
    }
  return uniqueArray;
  };


  // Return the results of applying an iterator to each element.
  _.map = function(collection, iterator) {
    var results = [];
    _.each(collection, function (item){
        results.push(iterator(item))
    })
    return results;
    // map() is a useful primitive iteration function that works a lot
    // like each(), but in addition to running the operation on all
    // the members, it also maintains an array of results.
  };

  // Takes an array of objects and returns and array of the values of
  // a certain property in it. E.g. take an array of people and return
  // an array of just their ages
  _.pluck = function(collection, key) {
    // TIP: map is really handy when you want to transform an array of
    // values into a new array of values. _.pluck() is solved for you
    // as an example of this.
    return _.map(collection, function(item){
      return item[key];
    });
  };

  // Reduces an array or object to a single value by repetitively calling
  // iterator(accumulator, item) for each item. accumulator should be
  // the return value of the previous iterator call.
  //  
  // You can pass in a starting value for the accumulator as the third argument
  // to reduce. If no starting value is passed, the first element is used as
  // the accumulator, and is never passed to the iterator. In other words, in
  // the case where a starting value is not passed, the iterator is not invoked
  // until the second element, with the first element as it's second argument.
  //  
  // Example:
  //   var numbers = [1,2,3];
  //   var sum = _.reduce(numbers, function(total, number){
  //     return total + number;
  //   }, 0); // should be 6
  //  
  //   var identity = _.reduce([5], function(total, number){
  //     return total + number * number;
  //   }); // should be 5, regardless of the iterator function passed in
  //          No accumulator is given so the first element is used.
  _.reduce = function(collection, iterator, accumulator) {
    _.each(collection, function (item) {
      if (accumulator === undefined) {
        accumulator = item;
      }
      else {
        accumulator = iterator(accumulator, item);
      }
    });
    return accumulator;
  };

  // Determine if the array or object contains a given value (using `===`).
  _.contains = function(collection, target) {
    // TIP: Many iteration problems can be most easily expressed in
    // terms of reduce(). Here's a freebie to demonstrate!
    return _.reduce(collection, function(wasFound, item) {
      if (wasFound) {
        return true;
      }
      return item === target;
    }, false);
  };


  // Determine whether all of the elements match a truth test.
  _.every = function(collection, iterator) {
    // TIP: Try re-using reduce() here.
    if (iterator === undefined) {
      iterator = function (item) {return item === true;}
    }
     
     return _.reduce(collection, function(wasFound, item) {
      if (wasFound === false) {
        return false;
      }
      return Boolean(iterator(item));
    }, true);
     
  };

  // Determine whether any of the elements pass a truth test. If no iterator is
  // provided, provide a default one
  _.some = function(collection, iterator) { //use every to see if see if every element fails the test
      if (iterator === undefined) {
      iterator = function (item) {return item === true;}
    }
      return !_.every(collection, function (item) {return !iterator(item)})
  };


  /**
   * OBJECTS
   * =======
   *
   * In this section, we'll look at a couple of helpers for merging objects.
   */

  // Extend a given object with all the properties of the passed in
  // object(s).
  //
  // Example:
  //   var obj1 = {key1: "something"};
  //   _.extend(obj1, {
  //     key2: "something new",
  //     key3: "something else new"
  //   }, {
  //     bla: "even more stuff"
  //   }); // obj1 now contains key1, key2, key3 and bla
  _.extend = function(obj) {
    _.each(arguments, function(source) {
        for (var key in source) {
            obj[key] = source[key];
          }
    });
    return obj;
  };

  // Like extend, but doesn't ever overwrite a key that already
  // exists in obj
  _.defaults = function(obj) { //a conditional extend
    _.each(arguments, function(source) {
        for (var key in source) {
          if (!(key in obj)) { <commit_msg>modofications<commit_after>(function() {
  'use strict';

  window._ = {};

  // Returns whatever value is passed as the argument. T
  _.identity = function(val) {
    return val;
  };

  /**
   * COLLECTIONS
   * ===========
   */

  // Return an array of the first n elements of an array. If n is undefined,
  // return just the first element.
  _.first = function(array, n) {
    return n === undefined ? array[0] : array.slice(0, n);
  };

  // Like first, but for the last elements. If n is undefined, return just the
  // last element.
  _.last = function(array, n) {
    if (n > array.length) {
    return array;
  }
    else { 
      return n === undefined ? array[array.length - 1] : array.slice(array.length - n);
    }
  };

  // Call iterator(value, key, collection) for each element of collection.
  // Accepts both arrays and objects.
  //
  // Note: _.each does not have a return value, but rather simply runs the
  // iterator function over each item in the input collection.
  _.each = function(collection, iterator) {
     if(Array.isArray(collection) === true){
         for (var i =0; i < collection.length; i++) {
         iterator(collection[i], i, collection);
         }
      } 
      else {
        for(var key in collection){
        iterator(collection[key], key, collection);
        }
      }
  };

  // Returns the index at which value can be found in the array, or -1 if value
  // is not present in the array.
  _.indexOf = function(array, target){
    var result = -1;

    _.each(array, function(item, index) {
      if (item === target && result === -1) {
        result = index;
      }
    });

    return result;
  };

  // Return all elements of an array that pass a truth test.
  _.filter = function(collection, test) {
    var results = [];
    _.each(collection, function (item){
      if (test(item)) {
        results.push(item)
      }
    })
    return results;
  };

  // Return all elements of an array that don't pass a truth test.
  _.reject = function(collection, test) {
    // We can re-use filter here - look for every element that fails a truth test
    return _.filter(collection, function (item){return !test(item)});
   
  };

  // Produce a duplicate-free version of the array.
  _.uniq = function(array) {
    var uniqueArray = [];
    var trackerObj = {}; //use a tracker object to remember what we have seen in the array previously.
    for (var i = 0; i < array.length; i ++) {
      trackerObj[array[i]] = array[i]
    };
    for (var key in trackerObj) {
      uniqueArray.push(trackerObj[key])
    }
  return uniqueArray;
  };


  // Return the results of applying an iterator to each element.
  _.map = function(collection, iterator) {
    var results = [];
    _.each(collection, function (item){
        results.push(iterator(item))
    })
    return results;
  };

  // Takes an array of objects and returns and array of the values of
  // a certain property in it. E.g. take an array of people and return
  // an array of just their ages
  _.pluck = function(collection, key) {
    return _.map(collection, function(item){
      return item[key];
    });
  };

  // Reduces an array or object to a single value by repetitively calling
  // iterator(accumulator, item) for each item. accumulator should be
  // the return value of the previous iterator call.
  //  
  // You can pass in a starting value for the accumulator as the third argument
  // to reduce. If no starting value is passed, the first element is used as
  // the accumulator, and is never passed to the iterator. In other words, in
  // the case where a starting value is not passed, the iterator is not invoked
  // until the second element, with the first element as it's second argument.
  //  
  // Example:
  //   var numbers = [1,2,3];
  //   var sum = _.reduce(numbers, function(total, number){
  //     return total + number;
  //   }, 0); // should be 6
  //  
  //   var identity = _.reduce([5], function(total, number){
  //     return total + number * number;
  //   }); // should be 5, regardless of the iterator function passed in
  //          No accumulator is given so the first element is used.
  _.reduce = function(collection, iterator, accumulator) {
    _.each(collection, function (item) {
      if (accumulator === undefined) {
        accumulator = item;
      }
      else {
        accumulator = iterator(accumulator, item);
      }
    });
    return accumulator;
  };

  // Determine if the array or object contains a given value (using `===`).
  _.contains = function(collection, target) {
    // We can use reduce:
    return _.reduce(collection, function(wasFound, item) {
      if (wasFound) {
        return true;
      }
      return item === target;
    }, false);
  };


  // Determine whether all of the elements match a truth test. If no iterator is passed in, we simply check if the item returns a true value
  _.every = function(collection, iterator) {
    if (iterator === undefined) {
      iterator = function (item) {return item === true;}
    }
     
     return _.reduce(collection, function(wasFound, item) {
      if (wasFound === false) {
        return false;
      }
      return Boolean(iterator(item));
    }, true);
     
  };

  // Determine whether any of the elements pass a truth test. If no iterator is
  // provided, provide a default one
  _.some = function(collection, iterator) { //use every to see if see if every element fails the test
      if (iterator === undefined) {
      iterator = function (item) {return item === true;}
    }
      return !_.every(collection, function (item) {return !iterator(item)})
  };


  /**
   * OBJECTS
   * =======
   */

  // Extend a given object with all the properties of the passed in
  // object(s).
  //
  // Example:
  //   var obj1 = {key1: "something"};
  //   _.extend(obj1, {
  //     key2: "something new",
  //     key3: "something else new"
  //   }, {
  //     bla: "even more stuff"
  //   }); // obj1 now contains key1, key2, key3 and bla
  _.extend = function(obj) {
    _.each(arguments, function(source) {
        for (var key in source) {
            obj[key] = source[key];
          }
    });
    return obj;
  };

  // Like extend, but doesn't ever overwrite a key that already
  // exists in obj
  _.defaults = function(obj) { //a conditional extend
    _.each(arguments, function(source) {
        for (var key in source) {
          if (!(key in obj)) { 
{'fraction_non_alphanumeric': 0.12133233532934132, 'fraction_numerical': 0.003592814371257485, 'mean_word_length': 2.3419209604802402, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '1252378', 'n_tokens_mistral': 3900, 'n_tokens_neox': 3793, 'n_words': 1495}