cc337bcd5f5a2d7a5e164d332ff9c704902f8c31
[platform/framework/web/crosswalk-tizen.git] /
1 var arrayMap = require('../internal/arrayMap'),
2     baseCallback = require('../internal/baseCallback'),
3     baseMap = require('../internal/baseMap'),
4     isArray = require('../lang/isArray');
5
6 /**
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).
10  *
11  * If a property name is provided for `iteratee` the created `_.property`
12  * style callback returns the property value of the given element.
13  *
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`.
17  *
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`.
21  *
22  * Many lodash methods are guarded to work as interatees for methods like
23  * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
24  *
25  * The guarded methods are:
26  * `ary`, `callback`, `chunk`, `clone`, `create`, `curry`, `curryRight`, `drop`,
27  * `dropRight`, `every`, `fill`, `flatten`, `invert`, `max`, `min`, `parseInt`,
28  * `slice`, `sortBy`, `take`, `takeRight`, `template`, `trim`, `trimLeft`,
29  * `trimRight`, `trunc`, `random`, `range`, `sample`, `some`, `uniq`, and `words`
30  *
31  * @static
32  * @memberOf _
33  * @alias collect
34  * @category Collection
35  * @param {Array|Object|string} collection The collection to iterate over.
36  * @param {Function|Object|string} [iteratee=_.identity] The function invoked
37  *  per iteration.
38  * @param {*} [thisArg] The `this` binding of `iteratee`.
39  * @returns {Array} Returns the new mapped array.
40  * @example
41  *
42  * function timesThree(n) {
43  *   return n * 3;
44  * }
45  *
46  * _.map([1, 2], timesThree);
47  * // => [3, 6]
48  *
49  * _.map({ 'a': 1, 'b': 2 }, timesThree);
50  * // => [3, 6] (iteration order is not guaranteed)
51  *
52  * var users = [
53  *   { 'user': 'barney' },
54  *   { 'user': 'fred' }
55  * ];
56  *
57  * // using the `_.property` callback shorthand
58  * _.map(users, 'user');
59  * // => ['barney', 'fred']
60  */
61 function map(collection, iteratee, thisArg) {
62   var func = isArray(collection) ? arrayMap : baseMap;
63   iteratee = baseCallback(iteratee, thisArg, 3);
64   return func(collection, iteratee);
65 }
66
67 module.exports = map;