From 1fd8505b2623ef1327f7d833403b1cedd7209392 Mon Sep 17 00:00:00 2001
From: rajroushan6714 <rajubhai6714x@gmail.com>
Date: Fri, 25 Aug 2023 11:53:10 +0530
Subject: [PATCH] test 12 completed

---
 12_findTheOldest/findTheOldest.js      | 23 +++++++++++++++++++++--
 12_findTheOldest/findTheOldest.spec.js |  4 ++--
 2 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/12_findTheOldest/findTheOldest.js b/12_findTheOldest/findTheOldest.js
index 366856a..df41532 100644
--- a/12_findTheOldest/findTheOldest.js
+++ b/12_findTheOldest/findTheOldest.js
@@ -1,5 +1,24 @@
-const findTheOldest = function() {
-
+const findTheOldest = function(people) {
+    let res;
+    let maxAge = 0;
+    let n = people.length;
+    for(let i = 0 ;i < n ; i++){
+        let birth = people[i].yearOfBirth;
+        let death;
+        if(people[i].yearOfDeath ==  undefined){
+            const d = new Date() ;
+            death =  d.getFullYear();
+        }
+        else {
+            death = people[i].yearOfDeath;
+        }
+        let age = death - birth;
+        if(age > maxAge){
+            maxAge = age;
+            res = people[i];
+        }
+    }
+    return res;
 };
 
 // Do not edit below this line
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",