function sortByAge(arr) {
let ageSorted = arr.sort(function(a, b) {
return Object.fromEntries(a).age - Object.fromEntries(b).age
});
// Arrange by young age. it's working well.
let result = [];
let names = ageSorted.filter(function (el) {
if(Array.isArray(el)){
result.push(firstName.concat(lastName));
}
return result;
});
return names;
}
However, the bottom function is not working. It cannot recognize the 'age' array, which causes an error. I am unsure why this happens.
I want to achieve something like this:
const avengers = [
[
['firstName', 'Captain'],
['lastName', 'Americano'],
['age', 105],
],
[
['firstName', 'Master'],
['lastName', 'Strange'],
['age', 120],
],
[
['firstName', 'IronyMan'],
['age', 55],
]
]
sortByAge(avengers);
// -> ['IronyMan','Captain Americano', 'Master Strange']