mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-04 17:07:49 +00:00
wip: migrate to bun
This commit is contained in:
30
src/map.ts
Normal file
30
src/map.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* 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;
|
||||
Reference in New Issue
Block a user