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` through
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`, `curry`, `curryRight`, `drop`, `dropRight`, `every`, `fill`,
16 * `invert`, `parseInt`, `random`, `range`, `rangeRight`, `slice`, `some`,
17 * `sortBy`, `take`, `takeRight`, `template`, `trim`, `trimEnd`, `trimStart`,
22 * @category Collection
23 * @param {Array|Object} collection The collection to iterate over.
24 * @param {Function|Object|string} [iteratee=_.identity] The function invoked per iteration.
25 * @returns {Array} Returns the new mapped array.
28 * function square(n) {
32 * _.map([4, 8], square);
35 * _.map({ 'a': 4, 'b': 8 }, square);
36 * // => [16, 64] (iteration order is not guaranteed)
39 * { 'user': 'barney' },
43 * // The `_.property` iteratee shorthand.
44 * _.map(users, 'user');
45 * // => ['barney', 'fred']
47 function map(collection, iteratee) {
48 var func = isArray(collection) ? arrayMap : baseMap;
49 return func(collection, baseIteratee(iteratee, 3));