Created
February 5, 2018 17:20
-
-
Save rafaelrinaldi/cd918e56e4c552b966d1c292e40653a7 to your computer and use it in GitHub Desktop.
This file contains 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
const combine = (...args) => | |
[].slice.call(args).reduce((next, value) => { | |
// Create an object with duplicates combined | |
const duplicates = Object.keys(value) | |
.filter(key => next.hasOwnProperty(key)) | |
.map(key => { | |
return { | |
[key]: Object.assign(value[key], next[key]) | |
}; | |
}) | |
.reduce( | |
(accumulator, current) => Object.assign(accumulator, current), | |
{} | |
); | |
// Create a new object with everything combined together | |
return Object.assign(next, value, duplicates); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment