1 var arrayMap = require('../internal/arrayMap'),
2 baseCallback = require('../internal/baseCallback'),
3 baseMap = require('../internal/baseMap'),
4 isArray = require('../lang/isArray');
7 * Creates an array of values by running each element in `collection` through
8 * `iteratee`. The `iteratee` is bound to `thisArg` and invoked with three
9 * arguments: (value, index|key, collection).
11 * If a property name is provided for `iteratee` the created `_.property`
12 * style callback returns the property value of the given element.
14 * If a value is also provided for `thisArg` the created `_.matchesProperty`
15 * style callback returns `true` for elements that have a matching property
16 * value, else `false`.
18 * If an object is provided for `iteratee` the created `_.matches` style
19 * callback returns `true` for elements that have the properties of the given
20 * object, else `false`.
22 * Many lodash methods are guarded to work as iteratees for methods like
23 * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
25 * The guarded methods are:
26 * `ary`, `callback`, `chunk`, `clone`, `create`, `curry`, `curryRight`,
27 * `drop`, `dropRight`, `every`, `fill`, `flatten`, `invert`, `max`, `min`,
28 * `parseInt`, `slice`, `sortBy`, `take`, `takeRight`, `template`, `trim`,
29 * `trimLeft`, `trimRight`, `trunc`, `random`, `range`, `sample`, `some`,
30 * `sum`, `uniq`, and `words`
35 * @category Collection
36 * @param {Array|Object|string} collection The collection to iterate over.
37 * @param {Function|Object|string} [iteratee=_.identity] The function invoked
39 * @param {*} [thisArg] The `this` binding of `iteratee`.
40 * @returns {Array} Returns the new mapped array.
43 * function timesThree(n) {
47 * _.map([1, 2], timesThree);
50 * _.map({ 'a': 1, 'b': 2 }, timesThree);
51 * // => [3, 6] (iteration order is not guaranteed)
54 * { 'user': 'barney' },
58 * // using the `_.property` callback shorthand
59 * _.map(users, 'user');
60 * // => ['barney', 'fred']
62 function map(collection, iteratee, thisArg) {
63 var func = isArray(collection) ? arrayMap : baseMap;
64 iteratee = baseCallback(iteratee, thisArg, 3);
65 return func(collection, iteratee);