jQuery plugin: JavaScript like Array.reduce for plain objects
npm install jquery-reduce-objectPlain JavaScript objects reduce as known from the Array.prototype
jquery.reduce-object.min.js` only, be sure jQuery is part of your Project.
You will get it here:
* http://jquery.com/download/ $3
* Download
*
` npm install `
$3
*
` node server.js `
* Open your browser at `localhost:1234 `$3
`js
var result = $.reduceObject(obj, callback, acc);
`
The `reduceObject` function takes following arguments:
`c2hs
obj: {Object} -> the object to reduce
callback: {function} -> the function to reduce with
acc: {*} -> the initial value given the first iteration as 'dest' argument
`
The ` callback ` function receives following arguments:
`c2hs
dest -> previous value
curr -> actual value in iteration
key -> actual key in iteration
obj -> the original object
`
$3
* Include
`jquery.reduce-object.min.js` into your Project`js
var objA = {
keyA = { value: 2 },
keyB = { value: 9 }
};var result = $.reduceObject(objA, function(dest, curr, key, obj) {
dest += curr;
return dest;
}, { value: 31 });
console.log(result);
// { value: 42 }
``* Patrick Gräf - graef685@googlemail.com