Created
July 20, 2017 17:04
-
-
Save jeyziel/25b6d3f2ccfb055374e3434850274f10 to your computer and use it in GitHub Desktop.
This file contains 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 | |
} | |
] | |
//2a | |
console.log('================LETRA a===============') | |
const maiorQueZero = produtos.filter( produtos => produtos.qtd > 0 ) | |
console.log( maiorQueZero ) | |
console.log('================LETRA B===============') | |
//2b | |
const idSubTotal = produto =>({ id: produto.id , subTotal: produto.preco * produto.qtd }) | |
const novoArray = produtos.map( idSubTotal ) | |
console.log( novoArray ) | |
console.log('================LETRA C===============') | |
//2c | |
const soma = ( anterior, atual ) => anterior + atual.subTotal | |
const somaSubTotais = novoArray.reduce( soma ,0) | |
console.log(somaSubTotais) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Certinho.