Skip to content

Instantly share code, notes, and snippets.

@marmeladze
Last active March 17, 2021 19:51
Show Gist options
  • Select an option

  • Save marmeladze/132c534310c5c6731961f65e57f2415c to your computer and use it in GitHub Desktop.

Select an option

Save marmeladze/132c534310c5c6731961f65e57f2415c to your computer and use it in GitHub Desktop.
interesting optional parameter decomposition
function foo(items, {shipping = 1, discount = 0} = {}) {
if (items == null || items.length === 0) return 0;
const s = items.reduce((total, item) => total+item );
const d = 1*discount;
return s+shipping-d;
}
// foo([1,2,3]) => 1+2+3+(shipping = 1) = 7
/**
put objects soon
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment