Created
July 20, 2017 00:17
-
-
Save elyssonmr/d4636115d3d310e7b0e6a140c548b8fa to your computer and use it in GitHub Desktop.
Exercício 2
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 | |
} | |
] | |
const prodQtdMaiorZero = produtos.filter(produto => produto.qtd > 0) | |
console.log("Produtos Qtd > 0:\n", prodQtdMaiorZero) | |
const produtoSubTotais = produtos.map(prod => { | |
return {id: prod.id, subtotal: prod.qtd * prod.preco} | |
}) | |
console.log("Subtotais:\n", produtoSubTotais) | |
const precos = produtoSubTotais.map(prod => prod.subtotal) | |
const somatorioSubtotais = precos.reduce( | |
(anterior, atual) => { | |
return atual + anterior | |
}, 0) | |
console.log("Somatório:\n", somatorioSubtotais) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Certinho