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