2024-01-11 20:52:09 +00:00
|
|
|
const findTheOldest = function(array) {
|
|
|
|
const oldest = array.sort((a, b) => {
|
2024-01-11 20:57:16 +00:00
|
|
|
let yearNow = (new Date()).getFullYear();
|
|
|
|
let ageA = ((a.yearOfDeath) ? a.yearOfDeath : yearNow) - a.yearOfBirth;
|
|
|
|
let ageB = ((b.yearOfDeath) ? b.yearOfDeath : yearNow) - b.yearOfBirth;
|
2024-01-11 20:52:09 +00:00
|
|
|
return (ageA > ageB) ? -1 : 1;
|
|
|
|
})[0];
|
|
|
|
return oldest;
|
2024-01-11 08:52:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Do not edit below this line
|
|
|
|
module.exports = findTheOldest;
|