Created
July 19, 2017 20:50
-
-
Save diogomascarenha/8a13ee464e299eb990235220e13eaad6 to your computer and use it in GitHub Desktop.
DevPleno - FullstackAcademy - Exercício 02
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 | |
| } | |
| ]; | |
| let produtosMaiorQueZero = produtos.filter(function(item){ return item.qtd > 0}); | |
| let produtosSubTotal = produtos.map(function(item){ return {id: item.id, subtotal: (item.qtd * item.preco)}}); | |
| let produtosSumSubTotal = produtos.map(function(item){ return (item.qtd * item.preco)}).reduce(function(anterior, atual){return anterior + atual}); | |
| console.log(produtosMaiorQueZero); | |
| console.log(produtosSubTotal); | |
| console.log(produtosSumSubTotal); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Certinho