<commit_before>'use strict';

export function backwards<T>(array: T[], callback: (el: T) => any) {
  for(var i = array.length - 1; i >= 0; i--) {
    callback(array[i]);
  }
}

export function each<T>(array: T[], callback: (el: T) => any) {
  for(var i = 0, l = array.length; i < l; i++) {
    callback(array[i]);
  }
}

export function safeEach<T>(array: T[], callback: (el: T) => any) {
  for(var i = 0, l = array.length; i < l; i++) {
    var curr = array[i];
    if(curr != null) callback(curr);
  }
}

export function remove<T>(array: T[], item: T) {
  for(var i = 0, l = array.length; i < l; i++) {
    if(array[i] === item) {
      array.splice(i, 1);
      return;
    }
  }
}

export function nullify<T>(array: T[], item: T) {
  for(var i = 0, l = array.length; i < l; i++) {
    if(array[i] === item) {
      array[i] = null;
      return;
    }
  }
}

export function compact<T>(array: T[]) {
  var start = -1,
      runLength = 0,
      inRun = false;

  for(var i = 0, l = array.length; i < l; i++) {
    if(array[i] === null) {
      if(!inRun) {
        inRun = true;
        start = i;
      }
    } else if(inRun) {
      runLength = i - start;
      array.splice(start, runLength);
      i -= runLength;
      l -= runLength;
      inRun = false;
    }
  }

  // Clean up at end
  if(inRun) array.splice(start, i - start);
}

export interface Constructor {
  (): void;
}

export function extend(Klass: Constructor, OtherKlass: Constructor) {
  var Temp: any = function() {};
  Temp.prototype = Klass.prototype;
  OtherKlass.prototype = new Temp();
  OtherKlass.prototype.constructor = OtherKlass;
  return OtherKlass;
}<commit_msg>compact() now also removes undefined values<commit_after>'use strict';

export function backwards<T>(array: T[], callback: (el: T) => any) {
  for(var i = array.length - 1; i >= 0; i--) {
    callback(array[i]);
  }
}

export function each<T>(array: T[], callback: (el: T) => any) {
  for(var i = 0, l = array.length; i < l; i++) {
    callback(array[i]);
  }
}

export function safeEach<T>(array: T[], callback: (el: T) => any) {
  for(var i = 0, l = array.length; i < l; i++) {
    var curr = array[i];
    if(curr != null) callback(curr);
  }
}

export function remove<T>(array: T[], item: T) {
  for(var i = 0, l = array.length; i < l; i++) {
    if(array[i] === item) {
      array.splice(i, 1);
      return;
    }
  }
}

export function nullify<T>(array: T[], item: T) {
  for(var i = 0, l = array.length; i < l; i++) {
    if(array[i] === item) {
      array[i] = null;
      return;
    }
  }
}

export function compact<T>(array: T[]) {
  var start = -1,
      runLength = 0,
      inRun = false;

  for(var i = 0, l = array.length; i < l; i++) {
    if(array[i] == null) {
      if(!inRun) {
        inRun = true;
        start = i;
      }
    } else if(inRun) {
      runLength = i - start;
      array.splice(start, runLength);
      i -= runLength;
      l -= runLength;
      inRun = false;
    }
  }

  // Clean up at end
  if(inRun) array.splice(start, i - start);
}

export interface Constructor {
  (): void;
}

export function extend(Klass: Constructor, OtherKlass: Constructor) {
  var Temp: any = function() {};
  Temp.prototype = Klass.prototype;
  OtherKlass.prototype = new Temp();
  OtherKlass.prototype.constructor = OtherKlass;
  return OtherKlass;
}
{'fraction_non_alphanumeric': 0.18184550646227832, 'fraction_numerical': 0.006011421701232342, 'mean_word_length': 2.586206896551724, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 23, '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': '1745068', 'n_tokens_mistral': 1255, 'n_tokens_neox': 1241, 'n_words': 335}