source: node_modules/es-toolkit/dist/compat/array/forEach.js

Last change on this file 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
3Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
5const identity = require('../../function/identity.js');
6const range = require('../../math/range.js');
7const isArrayLike = require('../predicate/isArrayLike.js');
8
9function 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
25exports.forEach = forEach;
Note: See TracBrowser for help on using the repository browser.