diff --git a/12_findTheOldest/findTheOldest.js b/12_findTheOldest/findTheOldest.js index 366856a..8cf8e31 100644 --- a/12_findTheOldest/findTheOldest.js +++ b/12_findTheOldest/findTheOldest.js @@ -1,5 +1,10 @@ -const findTheOldest = function() { - +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