12345678910111213141516171819202122232425262728293031 |
- 'use strict';
- var makeIterator = require('make-iterator');
- var forOwn = require('for-own');
- module.exports = function reduce(target, fn, acc, thisArg) {
- var first = arguments.length > 2;
- if (target && !Object.keys(target).length && !first) {
- return null;
- }
- var iterator = makeIterator(fn, thisArg);
- forOwn(target, function(value, key, orig) {
- if (!first) {
- acc = value;
- first = true;
- } else {
- acc = iterator(acc, value, key, orig);
- }
- });
- return acc;
- };
|