diff --git a/12_findTheOldest/findTheOldest.js b/12_findTheOldest/findTheOldest.js index 8cf8e31..a7f9422 100644 --- a/12_findTheOldest/findTheOldest.js +++ b/12_findTheOldest/findTheOldest.js @@ -1,7 +1,8 @@ const findTheOldest = function(array) { const oldest = array.sort((a, b) => { - let ageA = a.yearOfDeath - a.yearOfBirth; - let ageB = b.yearOfDeath - b.yearOfBirth; + let yearNow = (new Date()).getFullYear(); + let ageA = ((a.yearOfDeath) ? a.yearOfDeath : yearNow) - a.yearOfBirth; + let ageB = ((b.yearOfDeath) ? b.yearOfDeath : yearNow) - b.yearOfBirth; return (ageA > ageB) ? -1 : 1; })[0]; return oldest; diff --git a/12_findTheOldest/findTheOldest.spec.js b/12_findTheOldest/findTheOldest.spec.js index 732faaa..dab0d20 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 person with the greatest age if someone is still living', () => { + test('finds the person with the greatest age 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 person with the greatest age if the OLDEST is still living', () => { + test('finds the person with the greatest age if the OLDEST is still living', () => { const people = [ { name: "Carly",