diff --git a/12_findTheOldest/findTheOldest.js b/12_findTheOldest/findTheOldest.js index 366856a..89d01be 100644 --- a/12_findTheOldest/findTheOldest.js +++ b/12_findTheOldest/findTheOldest.js @@ -1,6 +1,18 @@ -const findTheOldest = function() { - -}; +const findTheOldest = function(people){ + peopleSorted = people.sort((a, b)=> + (getAge(a) > getAge(b)) ? + -1: + 1 + ); + return(peopleSorted[0]); +} +function getAge(person){ + let death = person.yearOfDeath; + if(!death){ + death = new Date().getFullYear(); + }; + return death - person.yearOfBirth; +} // Do not edit below this line module.exports = findTheOldest; diff --git a/12_findTheOldest/findTheOldest.spec.js b/12_findTheOldest/findTheOldest.spec.js index 06aec70..75823d6 100644 --- a/12_findTheOldest/findTheOldest.spec.js +++ b/12_findTheOldest/findTheOldest.spec.js @@ -21,7 +21,7 @@ describe('findTheOldest', () => { ] expect(findTheOldest(people).name).toBe('Ray'); }); - test.skip('finds the oldest person if someone is still living', () => { + test('finds the oldest person if someone is still living', () => { const people = [ { name: "Carly", @@ -40,7 +40,7 @@ describe('findTheOldest', () => { ] expect(findTheOldest(people).name).toBe('Ray'); }); - test.skip('finds the oldest person if the OLDEST is still living', () => { + test('finds the oldest person if the OLDEST is still living', () => { const people = [ { name: "Carly",