Skip to content

Instantly share code, notes, and snippets.

@argentinaluiz
Created May 7, 2018 18:01
Show Gist options
  • Save argentinaluiz/7ad6982e4ee73b0fba77447708402096 to your computer and use it in GitHub Desktop.
Save argentinaluiz/7ad6982e4ee73b0fba77447708402096 to your computer and use it in GitHub Desktop.
class Cart{
colecao = [
{id: 1, name: 'client1'},
{id: 2, name: 'client1'},
{id: 3, name: 'client1'},
];
add(product){
let subcolecao = this.colecao.filter((item) => item.id === product.id);
if(subcolecao.length){
subcolecao[0].quantidade++;
return;
}
this.colecao.push(product);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment