source: node_modules/es-toolkit/dist/compat/array/reduceRight.js

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

Added visualizations

  • Property mode set to 100644
File size: 1.2 KB
RevLine 
[a762898]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 reduceRight(collection, iteratee = identity.identity, accumulator) {
10 if (!collection) {
11 return accumulator;
12 }
13 let keys;
14 let startIndex;
15 if (isArrayLike.isArrayLike(collection)) {
16 keys = range.range(0, collection.length).reverse();
17 if (accumulator == null && collection.length > 0) {
18 accumulator = collection[collection.length - 1];
19 startIndex = 1;
20 }
21 else {
22 startIndex = 0;
23 }
24 }
25 else {
26 keys = Object.keys(collection).reverse();
27 if (accumulator == null) {
28 accumulator = collection[keys[0]];
29 startIndex = 1;
30 }
31 else {
32 startIndex = 0;
33 }
34 }
35 for (let i = startIndex; i < keys.length; i++) {
36 const key = keys[i];
37 const value = collection[key];
38 accumulator = iteratee(accumulator, value, key, collection);
39 }
40 return accumulator;
41}
42
43exports.reduceRight = reduceRight;
Note: See TracBrowser for help on using the repository browser.