parent
3b51e5dbef
commit
f22399369c
|
@ -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]
|
||||
// }
|
||||
|
|
Loading…
Reference in New Issue