Created
July 20, 2017 01:24
-
-
Save wescleymatos/d7a0daaaef2d8217d0b54d4e4a6b6e6f 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 | |
| } | |
| ] | |
| let novosProdutos = produtos.filter(item => item.qtd > 0) | |
| console.log(novosProdutos) |
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 subTotais = produtos.map(item => { | |
| return { | |
| id: item.id, | |
| subTotal: (item.preco * item.qtd) | |
| } | |
| }) | |
| console.log(subTotais) |
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 somaSubTotais = produtos | |
| .map(item => item.preco * item.qtd) | |
| .reduce((anterior, atual) => anterior + atual, 0) | |
| console.log(somaSubTotais) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Certinho.