source: node_modules/es-toolkit/dist/compat/array/forEachRight.mjs

Last change on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 666 bytes
RevLine 
[a762898]1import { identity } from '../../function/identity.mjs';
2import { range } from '../../math/range.mjs';
3import { isArrayLike } from '../predicate/isArrayLike.mjs';
4
5function forEachRight(collection, callback = identity) {
6 if (!collection) {
7 return collection;
8 }
9 const keys = isArrayLike(collection) ? range(0, collection.length) : Object.keys(collection);
10 for (let i = keys.length - 1; i >= 0; i--) {
11 const key = keys[i];
12 const value = collection[key];
13 const result = callback(value, key, collection);
14 if (result === false) {
15 break;
16 }
17 }
18 return collection;
19}
20
21export { forEachRight };
Note: See TracBrowser for help on using the repository browser.