|
Last change
on this file since a762898 was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago |
|
Added visualizations
|
-
Property mode
set to
100644
|
|
File size:
803 bytes
|
| Line | |
|---|
| 1 | 'use strict';
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|---|
| 4 |
|
|---|
| 5 | const identity = require('../../function/identity.js');
|
|---|
| 6 | const range = require('../../math/range.js');
|
|---|
| 7 | const isArrayLike = require('../predicate/isArrayLike.js');
|
|---|
| 8 |
|
|---|
| 9 | function forEach(collection, callback = identity.identity) {
|
|---|
| 10 | if (!collection) {
|
|---|
| 11 | return collection;
|
|---|
| 12 | }
|
|---|
| 13 | const keys = isArrayLike.isArrayLike(collection) || Array.isArray(collection) ? range.range(0, collection.length) : Object.keys(collection);
|
|---|
| 14 | for (let i = 0; i < keys.length; i++) {
|
|---|
| 15 | const key = keys[i];
|
|---|
| 16 | const value = collection[key];
|
|---|
| 17 | const result = callback(value, key, collection);
|
|---|
| 18 | if (result === false) {
|
|---|
| 19 | break;
|
|---|
| 20 | }
|
|---|
| 21 | }
|
|---|
| 22 | return collection;
|
|---|
| 23 | }
|
|---|
| 24 |
|
|---|
| 25 | exports.forEach = forEach;
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.