diff --git a/findTheOldest/findTheOldest.js b/findTheOldest/findTheOldest.js index 80d830b..c56cd89 100644 --- a/findTheOldest/findTheOldest.js +++ b/findTheOldest/findTheOldest.js @@ -1,3 +1,4 @@ +// using reduce method const findTheOldest = function(array) { return array.reduce((oldest, currentPerson) => { const oldestAge = getAge(oldest.yearOfBirth, oldest.yearOfDeath) @@ -14,3 +15,20 @@ const getAge = function(birth, death) { } module.exports = findTheOldest + + +// option using sort method +// let findTheOldest = function(people) { +// const sorted = people.sort((a, b) => { +// if(b.yearOfDeath === undefined && b.yearOfBirth < a.yearOfBirth){ +// return 1 +// } +// if((a.yearOfDeath - a.yearOfBirth) < (b.yearOfDeath - b.yearOfBirth)){ +// return 1 +// } +// else{ +// return -1 +// } +// }) +// return sorted[0] +// }