index.js 280 B

123456789101112
  1. module.exports = function (xs, f) {
  2. if (xs.map) return xs.map(f);
  3. var res = [];
  4. for (var i = 0; i < xs.length; i++) {
  5. var x = xs[i];
  6. if (hasOwn.call(xs, i)) res.push(f(x, i, xs));
  7. }
  8. return res;
  9. };
  10. var hasOwn = Object.prototype.hasOwnProperty;