Skip to content

Instantly share code, notes, and snippets.

@mariorodriguespt
Created July 27, 2018 20:01
Show Gist options
  • Save mariorodriguespt/e25b8bf27954d2f4e4e0d75640845f75 to your computer and use it in GitHub Desktop.
Save mariorodriguespt/e25b8bf27954d2f4e4e0d75640845f75 to your computer and use it in GitHub Desktop.
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