0
I would like to create a function as simple as possible that receives an Array of Person objects (example format: {name: "Alex",age: 24}
) that a new one returns array only with objects Person who are aged between 20 and 30 years.
My code is this:
var pessoa = [{
nome: 'Diego',
age: 17,
},
{
nome: 'Natalia',
age: 12,
},
{
nome: 'David',
age: 27,
},
{
nome: 'Daniel',
age: 30,
},
];
function idade(pessoa) {
if (age => 20 && <= 30) {
(a partir daqui nao sei como fazer)
}
}
I don’t know if the code is right.
Just a detail that you are using the arrow function ("Arrow Function") that is only available starting with ES6. If you can’t use it, go back to
function() { return ...; }
inside the callback passed tofilter
.– nbkhope
That’s right, well commented @nbkhope =]
– BrTkCa