This commit is contained in:
BananaBJones 2021-12-07 19:53:19 -07:00
parent e6e4540b32
commit 3ff65cf665
4 changed files with 52 additions and 9 deletions

View File

@ -12,3 +12,5 @@ const fibonacci = function(Fn) {
// Do not edit below this line
module.exports = fibonacci;
console.log(fibonacci(5));

View File

@ -1,9 +1,12 @@
const getTheTitles = function(array) {
let titles = [];
for (i=0;i<array.length;i++) {
titles[i] = array[i].title;
}
return titles;
// let titles = [];
// for (i=0;i<array.length;i++) {
// titles[i] = array[i].title;
// }
// return titles;
return array.map(book => {
return book.title;
});
};
// Do not edit below this line

View File

@ -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

View File

@ -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",