This commit is contained in:
parent
e6e4540b32
commit
3ff65cf665
|
@ -12,3 +12,5 @@ const fibonacci = function(Fn) {
|
||||||
|
|
||||||
// Do not edit below this line
|
// Do not edit below this line
|
||||||
module.exports = fibonacci;
|
module.exports = fibonacci;
|
||||||
|
|
||||||
|
console.log(fibonacci(5));
|
|
@ -1,9 +1,12 @@
|
||||||
const getTheTitles = function(array) {
|
const getTheTitles = function(array) {
|
||||||
let titles = [];
|
// let titles = [];
|
||||||
for (i=0;i<array.length;i++) {
|
// for (i=0;i<array.length;i++) {
|
||||||
titles[i] = array[i].title;
|
// titles[i] = array[i].title;
|
||||||
}
|
// }
|
||||||
return titles;
|
// return titles;
|
||||||
|
return array.map(book => {
|
||||||
|
return book.title;
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// Do not edit below this line
|
// Do not edit below this line
|
||||||
|
|
|
@ -1,6 +1,44 @@
|
||||||
const findTheOldest = function(arry) {
|
let callNum = 0;
|
||||||
let deathYear = arry
|
|
||||||
|
|
||||||
|
|
||||||
|
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
|
// Do not edit below this line
|
||||||
|
|
|
@ -21,7 +21,7 @@ describe('findTheOldest', () => {
|
||||||
]
|
]
|
||||||
expect(findTheOldest(people).name).toBe('Ray');
|
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 = [
|
const people = [
|
||||||
{
|
{
|
||||||
name: "Carly",
|
name: "Carly",
|
||||||
|
@ -40,7 +40,7 @@ describe('findTheOldest', () => {
|
||||||
]
|
]
|
||||||
expect(findTheOldest(people).name).toBe('Ray');
|
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 = [
|
const people = [
|
||||||
{
|
{
|
||||||
name: "Carly",
|
name: "Carly",
|
||||||
|
|
Loading…
Reference in New Issue