_baseMap.js 668 B

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