<commit_before>// "use strict";

// Check if we are executing on the server
//XXX Would browserify minifier optimize this away if it wasn't a function?
exports.onServer = function(cb) {
  var server = (typeof(window) == 'undefined');
  // var server = !process.env.browser;
  if(server && cb) cb(server);
  return server;
};

// Check if we are executing in the browser
exports.onClient = function(cb) {
  var client = !exports.onServer();
  if(client && cb) cb(client);
  return client;
};

// Loop through objects and arrays
// Return false from callback to stop iteration
exports.each = function(items, cb) {
  for(var key in items) {
    var cancel = cb(items[key], key);
    if(cancel) return;
  }
};

// Return a copy the given array
// with each item replaced according to <cb>
exports.map = function(items, cb) {
  var out = Array.isArray(items) ? [] : {};
  exports.each(items, function(item, key) {
    out[key] = cb(item, key);
  });
  return out;
};

// Call the given function <n> times
exports.times = function(n, cb) {
  for(var i = 0; i < n; i++) {
    cb(i);
  }
};

// Invoke the named method on each item
exports.invoke = function(items, key) {
  var out = [];
  exports.each(items, function(item) {
    out.push(item[key]());
  });
  return out;
};

// Interleave the items of two arrays
exports.zip = function(items1, items2, cb) {
  exports.each(items1, function(item1, i) {
    cb(item1, items2[i]);
  });
};

// Select items fron an array or object that match the given condition
exports.select = function(items, cb, n) {
  var ary = Array.isArray(items);
  var out = ary ? [] : {};
  var i = 0;
  exports.each(items, function(item, key) {
    if(cb(item, key)) {
      if(ary) {
        out.push(item);
      } else {
        out[key] = item;
      }
    }
    if(n && ++i == n) return true;
  });
  return out;
};

// Check if all items match the given condition
exports.all = function(items, cb) {
  return exports.select(items, cb).length == items.length;
};

exports.last = function(items) {
  return items[items.length - 1];
};

// Check if <item> is a member of the array
exports.contains = function(items, item) {
  return items.indexOf(item) != -1;
};

// Merge two arrays
exports.union = function(items1, items2) {
  var out = [];
  exports.each(items1, function(item) {
    out.push(item);
  });
  exports.each(items2, function(item) {
    out.push(item);
  });
  return out;
};

// Shallow copy the given array<commit_msg>Added 'any' utility function<commit_after>// "use strict";

// Check if we are executing on the server
//XXX Would browserify minifier optimize this away if it wasn't a function?
exports.onServer = function(cb) {
  var server = (typeof(window) == 'undefined');
  // var server = !process.env.browser;
  if(server && cb) cb(server);
  return server;
};

// Check if we are executing in the browser
exports.onClient = function(cb) {
  var client = !exports.onServer();
  if(client && cb) cb(client);
  return client;
};

// Loop through objects and arrays
// Return true from callback to stop iteration
exports.each = function(items, cb) {
  for(var key in items) {
    var cancel = cb(items[key], key);
    if(cancel) return true;
  }
};

// Return a copy the given array or object
// with each item replaced according to <cb>
exports.map = function(items, cb) {
  var out = Array.isArray(items) ? [] : {};
  exports.each(items, function(item, key) {
    out[key] = cb(item, key);
  });
  return out;
};

// Call the given function <n> times
exports.times = function(n, cb) {
  for(var i = 0; i < n; i++) {
    cb(i);
  }
};

// Invoke the named method on each item
exports.invoke = function(items, key) {
  var out = [];
  exports.each(items, function(item) {
    out.push(item[key]());
  });
  return out;
};

// Interleave the items of two arrays
exports.zip = function(items1, items2, cb) {
  exports.each(items1, function(item1, i) {
    cb(item1, items2[i]);
  });
};

// Select items fron an array or object that match the given condition
exports.select = function(items, cb, n) {
  var ary = Array.isArray(items);
  var out = ary ? [] : {};
  var i = 0;
  exports.each(items, function(item, key) {
    if(cb(item, key)) {
      if(ary) {
        out.push(item);
      } else {
        out[key] = item;
      }
    }
    if(n && ++i == n) return true;
  });
  return out;
};

// Check if all items match the given condition
exports.all = function(items, cb) {
  return exports.select(items, cb).length == items.length;
};

// Check if any item matches the given condition
exports.any = function(items, cb) {
  return exports.each(items, function(item, key) {
    if(cb(item, key)) {
      return true;
    }
  })
};

// Return the last item in the given array
exports.last = function(items) {
  return items[items.length - 1];
};

// Check if <item> is a member of the array
exports.contains = function(items, item) {
  return items.indexOf(item) != -1;
};

// Merge two arrays
exports.union = function(items1, items2) {
  var out = [];
  exports.each(items1, function(item) {
    out.push(item);
  });
  exports.each(items2, function(item) {
    out.push(item);
  });
  return out;
};

// Shallow copy the given array
{'fraction_non_alphanumeric': 0.15341566962562717, 'fraction_numerical': 0.005403319181783096, 'mean_word_length': 3.1663987138263665, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, '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': '7096764', 'n_tokens_mistral': 1738, 'n_tokens_neox': 1723, 'n_words': 538}