<commit_before>/**
 * @ngdoc filter
 * @name flatten
 * @kind function
 *
 * @description
 * Flattens a nested array (the nesting can be to any depth).
 * If you pass shallow, the array will only be flattened a single level
 */

angular.module('a8m.flatten', [])
  .filter('flatten', function () {
    return function(collection, shallow) {
      //WIP, should be mote forgiving, add shallow option,
      //to be more elegant + test performance
      return flatten(collection);
    }
  });


function flatten(array, i) {
  i = i || 0;
  if(i >= array.length) return array;
  if(isArray(array[i])) {
    var temp = flatten(array[i]);
    return flatten(array.slice(0,i)
      .concat(temp)
      .concat(array.slice(i+1)), 0)
  }
  return flatten(array, i+1)
}<commit_msg>fix(flatten): fix flattenFilter, add shallow option<commit_after>/**
 * @ngdoc filter
 * @name flatten
 * @kind function
 *
 * @description
 * Flattens a nested array (the nesting can be to any depth).
 * If you pass shallow, the array will only be flattened a single level
 */

angular.module('a8m.flatten', [])
  .filter('flatten', function () {
    return function(collection, shallow) {

      shallow = shallow || false;
      collection = (isObject(collection)) ? toArray(collection)
        : collection;

      if(!isArray(collection)) {
        return collection;
      }

      return (!shallow) ? flatten(collection, 0) :
        [].concat.apply([], collection);
    }
  });

/**
 * flatten nested array (the nesting can be to any depth).
 * @param array {Array}
 * @param i {int}
 * @returns {Array}
 * @private
 */
function flatten(array, i) {
  i = i || 0;

  if(i >= array.length)
    return array;

  if(Array.isArray(array[i])) {
    return flatten(array.slice(0,i)
      .concat(array[i], array.slice(i+1)), i);
  }
  return flatten(array, i+1);
}
{'fraction_non_alphanumeric': 0.14744287268770404, 'fraction_numerical': 0.006528835690968444, 'mean_word_length': 3.1325842696629214, 'pattern_counts': {'":': 0, '<': 3, '<?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': '4870458', 'n_tokens_mistral': 607, 'n_tokens_neox': 592, 'n_words': 173}