8000 Add solution to 12_findTheOldest · Boxis/javascript-exercises@c0f5f31 · GitHub
[go: up one dir, main page]

Skip to content

Commit c0f5f31

Browse files
committed
Add solution to 12_findTheOldest
1 parent 6d21d2f commit c0f5f31

File tree

2 files changed

+19
-3
lines changed

2 file 8000 s changed

+19
-3
lines changed

12_findTheOldest/findTheOldest.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
1-
const findTheOldest = function() {
1+
const findTheOldest = function(array) {
2+
const date = new Date();
3+
console.log(date);
24

5+
const oldest = array.sort(function(a, b) {
6+
// Test to see if there are any undefined values, set to today's date
7+
if(a.yearOfDeath == undefined || b.yearOfDeath == undefined) {
8+
a.yearOfDeath = date;
9+
b.yearOfDeath = date;
10+
};
11+
12+
const lastGuy = a.yearOfDeath - a.yearOfBirth;
13+
const nextGuy = b.yearOfDeath - b.yearOfBirth;
14< 8000 /td>+
return lastGuy > nextGuy ? -1 : 1;
15+
}, 0);
16+
console.table(oldest);
17+
18+
return oldest[0];
319
};
420

521
// Do not edit below this line

12_findTheOldest/findTheOldest.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('findTheOldest', () => {
2121
]
2222
expect(findTheOldest(people).name).toBe('Ray');
2323
});
24-
test.skip('finds the oldest person if someone is still living', () => {
24+
test('finds the oldest person if someone is still living', () => {
2525
const people = [
2626
{
2727
name: "Carly",
@@ -40,7 +40,7 @@ describe('findTheOldest', () => {
4040
]
4141
expect(findTheOldest(people).name).toBe('Ray');
4242
});
43-
test.skip('finds the oldest person if the OLDEST is still living', () => {
43+
test('finds the oldest person if the OLDEST is still living', () => {
4444
const people = [
4545
{
4646
name: "Carly",

0 commit comments

Comments
 (0)
0