From 3faa9634ab26df90e5f73790eeba249d35cdf5ed Mon Sep 17 00:00:00 2001 From: NetMan <13informatyka14@gmail.com> Date: Thu, 11 Jan 2024 21:57:16 +0100 Subject: [PATCH] Passed all remaining tests in exercise 12 --- 12_findTheOldest/findTheOldest.js | 5 +++-- 12_findTheOldest/findTheOldest.spec.js | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) 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",