Created
July 27, 2018 20:01
-
-
Save mariorodriguespt/e25b8bf27954d2f4e4e0d75640845f75 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
const _ = require("lodash"); | |
const boat = { | |
color : { | |
back : "red", | |
front : { | |
noose : "grey", | |
hood : "blue" | |
} | |
} | |
} | |
const preferences = [ | |
{ | |
key : "color.back", | |
value : "purple" | |
}, | |
{ | |
key : "color.front.hood", | |
value : "yellow" | |
} | |
]; | |
const applyPreferences = ( boat , preferences ) => { | |
const customisedBoat = Object.assign( {} , boat ); | |
_.each( preferences , ( { key , value } ) => { | |
_.set( customisedBoat, key , value ); | |
}); | |
return customisedBoat; | |
} | |
console.log(applyPreferences( boat , preferences )); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment