Last active
July 20, 2017 14:32
-
-
Save sandrooliveira/786bc0042daafb829bc6a13696965c60 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const produtos = [ | |
{ | |
id: 1, | |
preco: 10.0, | |
qtd: 2 | |
}, | |
{ | |
id: 2, | |
preco: 10.0, | |
qtd: 2 | |
}, | |
{ | |
id: 3, | |
preco: 10.0, | |
qtd: 2 | |
}, | |
{ | |
id: 4, | |
preco: 10.0, | |
qtd: 0 | |
} | |
] | |
console.log("2a ============================") | |
const checkQtd = value => value.qtd > 0 | |
const prodComQtd = produtos.filter(checkQtd) | |
console.log(prodComQtd) | |
console.log("2b ============================") | |
const prodSubtotais = produtos.map((produto) =>{ | |
produto.subTotal = produto.qtd*produto.preco | |
produto.id | |
return produto | |
}); | |
console.log(prodSubtotais) | |
console.log("2c ============================") | |
const somaSubtotais = prodSubtotais.reduce((anterior,atual) => { | |
return anterior + atual.subTotal | |
},0) | |
console.log(somaSubtotais) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ah sim, agora ficou claro! Valeu!