From 2d76b4cb785ce547e0cd0d7fef7b4c9e66121a74 Mon Sep 17 00:00:00 2001 From: NetMan <13informatyka14@gmail.com> Date: Thu, 11 Jan 2024 21:52:09 +0100 Subject: [PATCH] Passed first test in exercise 12 --- 12_findTheOldest/findTheOldest.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/12_findTheOldest/findTheOldest.js b/12_findTheOldest/findTheOldest.js index 366856a..8cf8e31 100644 --- a/12_findTheOldest/findTheOldest.js +++ b/12_findTheOldest/findTheOldest.js @@ -1,5 +1,10 @@ -const findTheOldest = function() { - +const findTheOldest = function(array) { + const oldest = array.sort((a, b) => { + let ageA = a.yearOfDeath - a.yearOfBirth; + let ageB = b.yearOfDeath - b.yearOfBirth; + return (ageA > ageB) ? -1 : 1; + })[0]; + return oldest; }; // Do not edit below this line