1 var apply = require('./internal/apply'),
2 baseEach = require('./internal/baseEach'),
3 baseInvoke = require('./internal/baseInvoke'),
4 isArrayLike = require('./isArrayLike'),
5 isKey = require('./internal/isKey'),
6 rest = require('./rest');
9 * Invokes the method at `path` of each element in `collection`, returning
10 * an array of the results of each invoked method. Any additional arguments
11 * are provided to each invoked method. If `methodName` is a function it's
12 * invoked for, and `this` bound to, each element in `collection`.
16 * @category Collection
17 * @param {Array|Object} collection The collection to iterate over.
18 * @param {Array|Function|string} path The path of the method to invoke or
19 * the function invoked per iteration.
20 * @param {...*} [args] The arguments to invoke each method with.
21 * @returns {Array} Returns the array of results.
24 * _.invokeMap([[5, 1, 7], [3, 2, 1]], 'sort');
25 * // => [[1, 5, 7], [1, 2, 3]]
27 * _.invokeMap([123, 456], String.prototype.split, '');
28 * // => [['1', '2', '3'], ['4', '5', '6']]
30 var invokeMap = rest(function(collection, path, args) {
32 isFunc = typeof path == 'function',
34 result = isArrayLike(collection) ? Array(collection.length) : [];
36 baseEach(collection, function(value) {
37 var func = isFunc ? path : ((isProp && value != null) ? value[path] : undefined);
38 result[++index] = func ? apply(func, value, args) : baseInvoke(value, path, args);
43 module.exports = invokeMap;