source: imaps-frontend/node_modules/lodash-es/invokeMap.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.4 KB
Line 
1import apply from './_apply.js';
2import baseEach from './_baseEach.js';
3import baseInvoke from './_baseInvoke.js';
4import baseRest from './_baseRest.js';
5import isArrayLike from './isArrayLike.js';
6
7/**
8 * Invokes the method at `path` of each element in `collection`, returning
9 * an array of the results of each invoked method. Any additional arguments
10 * are provided to each invoked method. If `path` is a function, it's invoked
11 * for, and `this` bound to, each element in `collection`.
12 *
13 * @static
14 * @memberOf _
15 * @since 4.0.0
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.
22 * @example
23 *
24 * _.invokeMap([[5, 1, 7], [3, 2, 1]], 'sort');
25 * // => [[1, 5, 7], [1, 2, 3]]
26 *
27 * _.invokeMap([123, 456], String.prototype.split, '');
28 * // => [['1', '2', '3'], ['4', '5', '6']]
29 */
30var invokeMap = baseRest(function(collection, path, args) {
31 var index = -1,
32 isFunc = typeof path == 'function',
33 result = isArrayLike(collection) ? Array(collection.length) : [];
34
35 baseEach(collection, function(value) {
36 result[++index] = isFunc ? apply(path, value, args) : baseInvoke(value, path, args);
37 });
38 return result;
39});
40
41export default invokeMap;
Note: See TracBrowser for help on using the repository browser.