Advertisement
vinissh

flatMap

Jan 18th, 2021
639
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Map associado com concat[]
  2. const escola = [{
  3.     nome:'Turma M1',
  4.     alunos:[{
  5.         nome:'Gustavo',
  6.         nota:8.1
  7.     },{
  8.         nome:'Turma M2',
  9.         alunos:[{
  10.             nome:'Rebeca',
  11.             nota:8.9
  12.         }, {
  13.             nome:'Roberto',
  14.             nota:7.3
  15.         }]
  16.     }
  17.     ]
  18. }]
  19.  
  20.  
  21. const getNotaDoAluno  = aluno => aluno.nota
  22. const getNotasDaTurma = turma => turma.alunos.map(getNotaDoAluno)
  23. const notas1 = escola.map(getNotasDaTurma)
  24. console.log(notas1);
  25. console.log([].concat([8.1,8.3],8.9,7.3))
  26.  
  27. Array.prototype.flatMap = function(callback){
  28.     return Array.prototype.concat([], this.map(callback))
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement