I'm struggling to understand higher-order functions. I have an objects array and want to return the developer out of the following list that is the oldest. In case some have the same age, I want to return all of them.
let input = [
{ firstName: 'Gabriel', lastName: 'X.', country: 'Monaco', continent: 'Europe', age: 49, language: 'PHP' },
{ firstName: 'Odval', lastName: 'F.', country: 'Mongolia', continent: 'Asia', age: 38, language: 'Python' },
{ firstName: 'Emilija', lastName: 'S.', country: 'Lithuania', continent: 'Europe', age: 19, language: 'Python' },
{ firstName: 'Sou', lastName: 'B.', country: 'Japan', continent: 'Asia', age: 49, language: 'PHP' },
];
Output I'm looking for:
let output = [
{ firstName: 'Gabriel', lastName: 'X.', country: 'Monaco', continent: 'Europe', age: 49, language: 'PHP' },
{ firstName: 'Sou', lastName: 'B.', country: 'Japan', continent: 'Asia', age: 49, language: 'PHP' },
];
Here is my code:
let oldDevFirst = input.sort((a,b)=>ages= b.age-a.age)
let allOdldDev = oldDevFirst.filter(el=> el === el.age[0]) //oldest developer at el.age[0]
Basically I sorted the list with 'oldDevFirst' so that the oldest developer comes first. However, I don't know how I can compare every property to the first property to return all the developers, that have the same oldest age. Thanks for reading or even helping a beginner out!