From f22399369ce3ff7355680054c9f442ff64779648 Mon Sep 17 00:00:00 2001
From: Dovid Majowka <36450233+DoviMaj@users.noreply.github.com>
Date: Fri, 3 Jul 2020 00:34:17 +0300
Subject: [PATCH] Update findTheOldest.js

Added option using sort method
---
 findTheOldest/findTheOldest.js | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/findTheOldest/findTheOldest.js b/findTheOldest/findTheOldest.js
index 80d830b..c56cd89 100644
--- a/findTheOldest/findTheOldest.js
+++ b/findTheOldest/findTheOldest.js
@@ -1,3 +1,4 @@
+// using reduce method
 const findTheOldest = function(array) {
   return array.reduce((oldest, currentPerson) => {
     const oldestAge = getAge(oldest.yearOfBirth, oldest.yearOfDeath)
@@ -14,3 +15,20 @@ const getAge = function(birth, death) {
 }
 
 module.exports = findTheOldest
+
+
+// option using sort method
+// let findTheOldest = function(people) {
+//   const sorted = people.sort((a, b) => {
+//     if(b.yearOfDeath === undefined && b.yearOfBirth < a.yearOfBirth){
+//       return 1
+//     }
+//     if((a.yearOfDeath - a.yearOfBirth) < (b.yearOfDeath - b.yearOfBirth)){
+//       return 1
+//     }
+//     else{
+//       return -1
+//     }
+//   })
+//   return sorted[0]
+// }