|
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
|
| Line | |
|---|
| 1 | import { identity } from '../../function/identity.mjs';
|
|---|
| 2 | import { range } from '../../math/range.mjs';
|
|---|
| 3 | import { isArrayLike } from '../predicate/isArrayLike.mjs';
|
|---|
| 4 |
|
|---|
| 5 | function 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 |
|
|---|
| 21 | export { forEachRight };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.