Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

foldr.js 1.5KB

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