Created
March 4, 2021 22:43
-
-
Save stoneboyindc/bd53d8f6c6ddb03490edcd2bcd851e99 to your computer and use it in GitHub Desktop.
This file contains 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 addProductToCart({ name, priceInCents }, cart = {}) { | |
const selected = cart[name]; | |
if (selected) { | |
selected.quantity++; | |
} else { | |
cart[name] = { priceInCents, quantity: 1 }; | |
} | |
return cart; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment