Skip to content

Instantly share code, notes, and snippets.

@joelnet
Created March 1, 2019 07:29
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save joelnet/1abc665c56bf94fcf7152642844a9ac9 to your computer and use it in GitHub Desktop.
Save joelnet/1abc665c56bf94fcf7152642844a9ac9 to your computer and use it in GitHub Desktop.
const user2 = {
id: 200,
name: 'Vince Noir'
}
const user4 = {
id: 400,
name: 'Bollo',
quotes: ["I've got a bad feeling about this..."]
}
const setDefaults = ({ quotes = [], ...object}) =>
({ ...object, quotes })
setDefaults(user2)
//=> { id: 200, name: 'Vince Noir', quotes: [] }
setDefaults(user4)
//=> {
//=> id: 400,
//=> name: 'Bollo',
//=> quotes: ["I've got a bad feeling about this..."]
//=> }
@joelnet
Copy link
Author

joelnet commented Mar 18, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment