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.
32 lines
669 B
32 lines
669 B
2 years ago
|
/*!
|
||
|
* object.reduce <https://github.com/jonschlinkert/object.reduce>
|
||
|
*
|
||
|
* Copyright (c) 2014-2015, 2017, Jon Schlinkert.
|
||
|
* Released under the MIT License.
|
||
|
*/
|
||
|
|
||
|
'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;
|
||
|
};
|