source: node_modules/es-toolkit/dist/compat/array/forEachRight.js@ a762898

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: 794 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 forEachRight(collection, callback = identity.identity) {
10 if (!collection) {
11 return collection;
12 }
13 const keys = isArrayLike.isArrayLike(collection) ? range.range(0, collection.length) : Object.keys(collection);
14 for (let i = keys.length - 1; i >= 0; 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.forEachRight = forEachRight;
Note: See TracBrowser for help on using the repository browser.