3ffdd8ef42305389e7074f660060541a788621b0
[yaffs-website] / node_modules / grunt-uncss / node_modules / async / reduceRight.js
1 'use strict';
2
3 Object.defineProperty(exports, "__esModule", {
4   value: true
5 });
6 exports.default = reduceRight;
7
8 var _reduce = require('./reduce');
9
10 var _reduce2 = _interopRequireDefault(_reduce);
11
12 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
14 var slice = Array.prototype.slice;
15
16 /**
17  * Same as [`reduce`]{@link module:Collections.reduce}, only operates on `array` in reverse order.
18  *
19  * @name reduceRight
20  * @static
21  * @memberOf module:Collections
22  * @method
23  * @see [async.reduce]{@link module:Collections.reduce}
24  * @alias foldr
25  * @category Collection
26  * @param {Array} array - A collection to iterate over.
27  * @param {*} memo - The initial state of the reduction.
28  * @param {Function} iteratee - A function applied to each item in the
29  * array to produce the next step in the reduction. The `iteratee` is passed a
30  * `callback(err, reduction)` which accepts an optional error as its first
31  * argument, and the state of the reduction as the second. If an error is
32  * passed to the callback, the reduction is stopped and the main `callback` is
33  * immediately called with the error. Invoked with (memo, item, callback).
34  * @param {Function} [callback] - A callback which is called after all the
35  * `iteratee` functions have finished. Result is the reduced value. Invoked with
36  * (err, result).
37  */
38 function reduceRight(array, memo, iteratee, callback) {
39   var reversed = slice.call(array).reverse();
40   (0, _reduce2.default)(reversed, memo, iteratee, callback);
41 }
42 module.exports = exports['default'];