add findOldest Solutions

This commit is contained in:
Cody Loyd
2019-04-11 12:11:03 -05:00
parent c0ef28a362
commit ffa00275cc
3 changed files with 90 additions and 0 deletions
+16
View File
@@ -0,0 +1,16 @@
const findTheOldest = function(array) {
return array.reduce((oldest, currentPerson) => {
const oldestAge = getAge(oldest.yearOfBirth, oldest.yearOfDeath)
const currentAge = getAge(currentPerson.yearOfBirth, currentPerson.yearOfDeath)
return oldestAge < currentAge ? currentPerson : oldest
})
}
const getAge = function(birth, death) {
if (!death) {
death = new Date().getFullYear();
}
return death - birth;
}
module.exports = findTheOldest