Last active
March 17, 2021 19:51
-
-
Save marmeladze/132c534310c5c6731961f65e57f2415c to your computer and use it in GitHub Desktop.
interesting optional parameter decomposition
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
| 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