odin-js-fundamentals-part-5/12_findTheOldest/findTheOldest.js

12 lines
318 B
JavaScript

const findTheOldest = function(array) {
const oldest = array.sort((a, b) => {
let ageA = a.yearOfDeath - a.yearOfBirth;
let ageB = b.yearOfDeath - b.yearOfBirth;
return (ageA > ageB) ? -1 : 1;
})[0];
return oldest;
};
// Do not edit below this line
module.exports = findTheOldest;