From 3ff65cf6656a4037feb1ed10d7fe55ad56ead5df Mon Sep 17 00:00:00 2001 From: BananaBJones Date: Tue, 7 Dec 2021 19:53:19 -0700 Subject: [PATCH] up --- 10_fibonacci/fibonacci.js | 2 ++ 11_getTheTitles/getTheTitles.js | 13 +++++--- 12_findTheOldest/findTheOldest.js | 42 ++++++++++++++++++++++++-- 12_findTheOldest/findTheOldest.spec.js | 4 +-- 4 files changed, 52 insertions(+), 9 deletions(-) diff --git a/10_fibonacci/fibonacci.js b/10_fibonacci/fibonacci.js index 01f5642..01477ee 100644 --- a/10_fibonacci/fibonacci.js +++ b/10_fibonacci/fibonacci.js @@ -12,3 +12,5 @@ const fibonacci = function(Fn) { // Do not edit below this line module.exports = fibonacci; + +console.log(fibonacci(5)); \ No newline at end of file diff --git a/11_getTheTitles/getTheTitles.js b/11_getTheTitles/getTheTitles.js index 4f64f08..d14eee3 100644 --- a/11_getTheTitles/getTheTitles.js +++ b/11_getTheTitles/getTheTitles.js @@ -1,9 +1,12 @@ const getTheTitles = function(array) { - let titles = []; - for (i=0;i { + return book.title; + }); }; // Do not edit below this line diff --git a/12_findTheOldest/findTheOldest.js b/12_findTheOldest/findTheOldest.js index d7af4f8..3864276 100644 --- a/12_findTheOldest/findTheOldest.js +++ b/12_findTheOldest/findTheOldest.js @@ -1,6 +1,44 @@ -const findTheOldest = function(arry) { - let deathYear = arry +let callNum = 0; + +const findTheOldest = function(arry) { + let age = 0; + let oldest = { + age: 1, + }; + console.log("Round Num: " + callNum); + for (i = 0; i < arry.length; i++) { + if (!arry[i].yearOfDeath){ + let currentYear = new Date().getFullYear(); + age = currentYear - arry[i].yearOfBirth; + arry[i].age = age; + console.log("Carly's Age " + arry[i].age) + } + else { + age = arry[i].yearOfDeath - arry[i].yearOfBirth; + arry[i].age = age; + } + } + for (i = 0; i < arry.length; i++) { + // if (arry[i].age > arry[i+1].age && arry[i].age >= oldest.age) { + // oldest = arry[i]; + // console.log('true'); + // console.log(oldest); + // } + if (oldest.age > arry[i].age) { + oldest = oldest; + console.log('false'); + console.log(oldest); + } + else if (oldest.age < arry[i].age) { + oldest = arry[i]; + console.log('false if'); + console.log(oldest); + } + } + callNum++; + + return oldest; }; // Do not edit below this line diff --git a/12_findTheOldest/findTheOldest.spec.js b/12_findTheOldest/findTheOldest.spec.js index 06aec70..75823d6 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 oldest person if someone is still living', () => { + test('finds the oldest person 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 oldest person if the OLDEST is still living', () => { + test('finds the oldest person if the OLDEST is still living', () => { const people = [ { name: "Carly",