forked from codemix/fast.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreduceRight.js
24 lines (22 loc) · 865 Bytes
/
reduceRight.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
'use strict';
var reduceRightArray = require('./array/reduceRight'),
reduceRightObject = require('./object/reduceRight');
/**
* # Reduce Right
*
* A fast `.reduceRight()` implementation.
*
* @param {Array|Object} subject The array or object to reduce over.
* @param {Function} fn The reducer function.
* @param {mixed} initialValue The initial value for the reducer, defaults to subject[0].
* @param {Object} thisContext The context for the reducer.
* @return {Array|Object} The array or object containing the results.
*/
module.exports = function fastReduceRight (subject, fn, initialValue, thisContext) {
if (subject instanceof Array) {
return reduceRightArray(subject, fn, initialValue, thisContext);
}
else {
return reduceRightObject(subject, fn, initialValue, thisContext);
}
};