Skip to content

Instantly share code, notes, and snippets.

@stoneboyindc
Created March 4, 2021 22:43
Show Gist options
  • Save stoneboyindc/bd53d8f6c6ddb03490edcd2bcd851e99 to your computer and use it in GitHub Desktop.
Save stoneboyindc/bd53d8f6c6ddb03490edcd2bcd851e99 to your computer and use it in GitHub Desktop.
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