Last active
November 27, 2019 07:42
-
-
Save plugn/14f88ff9de3c1b17ad2256cca4708284 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function reduceObject( obj, reduceCallback, initialValue ) { | |
return Object.keys( obj ).reduce( function( acc, key, idx, arr ) { | |
return reduceCallback( acc, obj[key], key, obj ) | |
}, initialValue ) | |
} | |
var mapCollectionByProp = (list, fieldName) => list.reduce( (acc, v) => ({ ...acc, [v[fieldName]]: v }), {}) | |
/** | |
* returns new object with result of iterator() call for each property from keys | |
* @param {Object} object | |
* @param {Array} keys | |
* @param {Function} iterator | |
*/ | |
const updateObject = (object, keys, iterator = val => val) => | |
keys.reduce((acc, field) => ({ ...acc, [field]: iterator(object[field]) }), {...object}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment