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
// Objeto Inicial | |
const refeicao = { | |
id: 1, | |
descricao: 'Café da Manhã' | |
} | |
// Adicionando novos items | |
const adicionandoNovaPropriedade = { | |
...refeicao, | |
calorias: 600 |
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
// Objeto Inicial | |
const refeicao = { | |
id: 1, | |
descricao: 'Café da Manhã' | |
} | |
// Atualizando valores | |
const atualizandoRefeicao = { | |
...refeicao, | |
descricao: 'Café das 09hrs' |
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
// Objeto Inicial | |
const refeicao = { | |
id: 1, | |
descricao: 'Café da Manhã' | |
} | |
// Extraindo Valores | |
const { descricao } = refeicao | |
console.log(descricao) // Café da Manhã |
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
// Objeto Inicial | |
const refeicao = { | |
id: 1, | |
descricao: 'Café da Manhã' | |
} | |
// Destructuring + Rest - Removendo valores | |
const { id, ...refeicaoSemId } = refeicao | |
console.log(refeicaoSemId) // { descricao: 'Café da Manhã' } | |
console.log(id) // 1 |
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
// Arrays Iniciais | |
const refeicaoArray = [ | |
{ id: 1, descricao: 'Café da Manhã', calorias: 420 }, | |
{ id: 2, descricao: 'Almoço', calorias: 580 } | |
] | |
const novaRefeicao = { | |
id: 3, | |
descricao: 'Café da Tarde', | |
calorias: 280 |
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
// Atualizando item no array (.map) | |
const numeros = [1, 2, 3] | |
function dobrar (num) { | |
return num * 2 | |
} | |
const dobrarEs6 = num => num *2 | |
const numerosVezesDois = numeros.map(dobrarEs6) |
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
// array inicial | |
const refeicaoArray = [ | |
{ id: 1, descricao: 'Café da Manhã', calorias: 420 }, | |
{ id: 2, descricao: 'Almoço', calorias: 580 } | |
] | |
const novaRefeicao = { | |
id: 3, | |
descricao: 'Café da Tarde', | |
calorias: 280 |
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
// Objeto Inicial | |
const refeicaoArray = [ | |
{ id: 1, descricao: 'Café da Manhã', calorias: 420 }, | |
{ id: 2, descricao: 'Almoço', calorias: 580 } | |
] | |
// Removendo item no array refeicoes (.filter) | |
function filtro (refeicao) { | |
if (refeicao.id === 2) { | |
return true |
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
// Somando valores de arrays (.reduce) | |
const numeros2 = [1, 2, 3] | |
function soma (x, y) { | |
return x + y | |
} | |
const somaDosNumeros2 = numeros2.reduce(soma) | |
console.log(somaDosNumeros2) // 6 |
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 configPossibilities = [ [ 1 ], [ 1, 2 ], [ 1, 2, 3, 4 ] ] | |
const configPossibilities2 = { | |
ID_LINHA: [ 1 ], | |
ID_IMPLEMENTO: [ 1 , 2 ], | |
ID_COMPOSICAO: [ 1 , 2 , 3 , 4 ] | |
} | |
const desiredResult = [ | |
[1, 1, 1 ], |