1 var arrayMap = require('./_arrayMap'),
2 baseIteratee = require('./_baseIteratee'),
3 baseMap = require('./_baseMap'),
4 isArray = require('./isArray');
7 * Creates an array of values by running each element in `collection` thru
8 * `iteratee`. The iteratee is invoked with three arguments:
9 * (value, index|key, collection).
11 * Many lodash methods are guarded to work as iteratees for methods like
12 * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
14 * The guarded methods are:
15 * `ary`, `chunk`, `curry`, `curryRight`, `drop`, `dropRight`, `every`,
16 * `fill`, `invert`, `parseInt`, `random`, `range`, `rangeRight`, `repeat`,
17 * `sampleSize`, `slice`, `some`, `sortBy`, `split`, `take`, `takeRight`,
18 * `template`, `trim`, `trimEnd`, `trimStart`, and `words`
23 * @category Collection
24 * @param {Array|Object} collection The collection to iterate over.
25 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
26 * @returns {Array} Returns the new mapped array.
29 * function square(n) {
33 * _.map([4, 8], square);
36 * _.map({ 'a': 4, 'b': 8 }, square);
37 * // => [16, 64] (iteration order is not guaranteed)
40 * { 'user': 'barney' },
44 * // The `_.property` iteratee shorthand.
45 * _.map(users, 'user');
46 * // => ['barney', 'fred']
48 function map(collection, iteratee) {
49 var func = isArray(collection) ? arrayMap : baseMap;
50 return func(collection, baseIteratee(iteratee, 3));