|
Last change
on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago |
|
Added visualizations
|
-
Property mode
set to
100644
|
|
File size:
736 bytes
|
| Line | |
|---|
| 1 | import { identity } from '../../function/identity.mjs';
|
|---|
| 2 | import { range } from '../../math/range.mjs';
|
|---|
| 3 | import { isArrayLike } from '../predicate/isArrayLike.mjs';
|
|---|
| 4 | import { iteratee } from '../util/iteratee.mjs';
|
|---|
| 5 |
|
|---|
| 6 | function map(collection, _iteratee) {
|
|---|
| 7 | if (!collection) {
|
|---|
| 8 | return [];
|
|---|
| 9 | }
|
|---|
| 10 | const keys = isArrayLike(collection) || Array.isArray(collection) ? range(0, collection.length) : Object.keys(collection);
|
|---|
| 11 | const iteratee$1 = iteratee(_iteratee ?? identity);
|
|---|
| 12 | const result = new Array(keys.length);
|
|---|
| 13 | for (let i = 0; i < keys.length; i++) {
|
|---|
| 14 | const key = keys[i];
|
|---|
| 15 | const value = collection[key];
|
|---|
| 16 | result[i] = iteratee$1(value, key, collection);
|
|---|
| 17 | }
|
|---|
| 18 | return result;
|
|---|
| 19 | }
|
|---|
| 20 |
|
|---|
| 21 | export { map };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.