baseMap.js 696 B

1234567891011121314151617181920212223
  1. var baseEach = require('./baseEach'),
  2. isArrayLike = require('./isArrayLike');
  3. /**
  4. * The base implementation of `_.map` without support for callback shorthands
  5. * and `this` binding.
  6. *
  7. * @private
  8. * @param {Array|Object|string} collection The collection to iterate over.
  9. * @param {Function} iteratee The function invoked per iteration.
  10. * @returns {Array} Returns the new mapped array.
  11. */
  12. function baseMap(collection, iteratee) {
  13. var index = -1,
  14. result = isArrayLike(collection) ? Array(collection.length) : [];
  15. baseEach(collection, function(value, key, collection) {
  16. result[++index] = iteratee(value, key, collection);
  17. });
  18. return result;
  19. }
  20. module.exports = baseMap;