Last active
August 2, 2017 17:47
-
-
Save tosipaulo/b1f0a58b5fa1c0c60b9bf1bf58349d77 to your computer and use it in GitHub Desktop.
Exercício 2
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 | |
let filterProduto = produtos.filter((produto) => produto.qtd > 0) | |
console.log(filterProduto) |
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 | |
} | |
] | |
//2B | |
let subTotal = produtos.map((produto) => { | |
return { | |
id : produto.id, | |
subtotal: produto.preco * produto.qtd | |
} | |
}) | |
console.log(subTotal) |
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 | |
} | |
] | |
/ ************************************** / | |
let subTotalPreco = produtos | |
.map((produto) => produto.preco * produto.qtd) | |
.reduce((prev, next) => prev + next , 0) | |
console.log(subTotalPreco) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Certinho