Skip to content

Instantly share code, notes, and snippets.

@moondef
Last active June 28, 2018 17:50
Show Gist options
  • Save moondef/629572c347ec920ad328304e986a0868 to your computer and use it in GitHub Desktop.
Save moondef/629572c347ec920ad328304e986a0868 to your computer and use it in GitHub Desktop.
const addToCart = (cart, pokemon) => {
if (inCart(cart, pokemon)) {
cart.find(item => item.name === pokemon.name).count += 1;
} else {
pokemon['count'] = 1
cart.push(pokemon)
}
return cart
}
const inCart = (cart, pokemon) => cart.some(item => item['name'] === pokemon.name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment