0
Personal I have the following problem: how to subtract 2 arrays with Angularjs.
I’ve tried several ways and I couldn’t make that subtraction.
I am creating a product cart with dynamic optional in Angularjs
in that case the customer has made the following modification:
increment id 1004, 1000 decrease id 1001 added id 1002
original recipe:
[{"id":1004,"idproduto":3,"forma":"Alface","preco":1,"quantidade":1},{"id":1000,"idproduto":3,"forma":"Bacon","preco":2,"quantidade":1},{"id":1001,"idproduto":3,"forma":"Queijo Cheedar","preco":2,"quantidade":3}]
modified recipe:
[{"id":1004,"idproduto":3,"forma":"Alface","preco":1,"quantidade":2},{"id":1000,"idproduto":3,"forma":"Bacon","preco":2,"quantidade":2},{"id":1001,"idproduto":3,"forma":"Queijo Cheedar","preco":2,"quantidade":1},{"id":1002,"idproduto":2,"forma":"Bacon","preco":2,"quantidade":1}]
I need to reformulate this array because I need to show the changes in the shopping cart for the customer.
Product 500
+1 1004 (R$1,00)
+1 1000 (R$2,00)
+1 1002 (R$2,00)
-2 1001 (R$4,00)
Final recipe for the cart
[{"id":1004,"idproduto":3,"forma":"Alface","preco":1,"quantidade":1},{"id":1000,"idproduto":3,"forma":"Bacon","preco":2,"quantidade":1},{"id":1001,"idproduto":3,"forma":"Queijo Cheedar","preco":2,"quantidade":-2},{"id":1002,"idproduto":2,"forma":"Bacon","preco":2,"quantidade":1}]
And at the end would have to add the original array with the end to give low stock.
I’m correct in that logic?
blz I will test, but anyway quarreled!
– Willian
because it kind of didn’t work out the way I thought it would... test with the demo and it was the same example of yours... I’m missing a lot of data... the right way wouldn’t be the final recipe array not?
– Willian
@Willian the purpose of the operation is to expose the difference; you can combine the result with your original array as you wish.
– OnoSendai
so I was able to implement now give me a hint on how to turn an array = that of the final recipe
– Willian
Pow @Onosendai was thinking about this subject and that in the array[2] needed a reference to know which item is the modification... how would pull the rest of the items that are additional equal to bacon?
– Willian