This repository has been archived on 2026-03-28. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
StasisWarden-Legacy/node_modules/es-toolkit/dist/compat/array/forEachRight.mjs
T

22 lines
666 B
JavaScript

import { identity } from '../../function/identity.mjs';
import { range } from '../../math/range.mjs';
import { isArrayLike } from '../predicate/isArrayLike.mjs';
function forEachRight(collection, callback = identity) {
if (!collection) {
return collection;
}
const keys = isArrayLike(collection) ? range(0, collection.length) : Object.keys(collection);
for (let i = keys.length - 1; i >= 0; i--) {
const key = keys[i];
const value = collection[key];
const result = callback(value, key, collection);
if (result === false) {
break;
}
}
return collection;
}
export { forEachRight };