Permalink
Cannot retrieve contributors at this time
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
30 lines (28 sloc)
736 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Creates an array of values by running each element of `array` thru `iteratee`. | |
* The iteratee is invoked with three arguments: (value, index, array). | |
* | |
* @since 5.0.0 | |
* @category Array | |
* @param {Array} array The array to iterate over. | |
* @param {Function} iteratee The function invoked per iteration. | |
* @returns {Array} Returns the new mapped array. | |
* @example | |
* | |
* function square(n) { | |
* return n * n | |
* } | |
* | |
* map([4, 8], square) | |
* // => [16, 64] | |
*/ | |
function map(array, iteratee) { | |
let index = -1 | |
const length = array == null ? 0 : array.length | |
const result = new Array(length) | |
while (++index < length) { | |
result[index] = iteratee(array[index], index, array) | |
} | |
return result | |
} | |
export default map |