Last active
August 30, 2018 01:36
-
-
Save JorgeMadson/04859e5bece40ee9f22902d8f28de98c to your computer and use it in GitHub Desktop.
Revisão Javascript Programação Funcional Array 2 - Map
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
// Usando o array anterior | |
var prova = [ { aluno: 'Fogaça', nota: 9.5 }, | |
// ... | |
]; | |
var adiconaTipo = prova.map(function (item) { | |
if (item.aluno === 'Fogaça' || item.aluno === 'Paola' || item.aluno === 'Jacquin') { | |
item.tipo = 'Jurado'; | |
return item; | |
} | |
if (item.aluno === 'Ana Paula') { | |
item.tipo = 'Apresentador'; | |
return item; | |
} | |
item.tipo = 'Participante'; | |
return item; | |
}); | |
console.log(adiconaTipo); | |
// Resultado: | |
// [ { aluno: 'Fogaça', nota: 9.5, tipo: 'Jurado' }, | |
// { aluno: 'Paola', nota: 10, tipo: 'Jurado' }, | |
// { aluno: 'Jacquin', nota: 8, tipo: 'Jurado' }, | |
// { aluno: 'Mohamad', nota: 7, tipo: 'Participante' }, | |
// { aluno: 'Sofia', nota: 9, tipo: 'Participante' }, | |
// { aluno: 'Rita', nota: 9.5, tipo: 'Participante' }, | |
// { aluno: 'Ana Paula', nota: 7, tipo: 'Apresentador' }, | |
// { aluno: 'Vitória', nota: 10, tipo: 'Participante' } ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment