8000 Completed excercise 12 · 10h30/odin-javascript-exercises@22a6289 · GitHub
[go: up one dir, main page]

Skip to content

Commit 22a6289

Browse files
committed
Completed excercise 12
1 parent 8beb3b7 commit 22a6289

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

12_findTheOldest/findTheOldest.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,30 @@
1-
const findTheOldest = function() {
1+
const findTheOldest = function(people) {
2+
console.log(people)
3+
const sortByAge = people.sort((a,b) => {
4+
5+
if (!a.yearOfDeath) {
6+
let currentYear = new Date().getFullYear(); console.log(currentYear)
7+
ageOfa = currentYear - a.yearOfBirth
8+
}
9+
else {
10+
ageOfa = a.yearOfDeath - a.yearOfBirth
11+
}
12+
console.log(a.name + ": " + ageOfa)
213

14+
if (!b.yearOfDeath) {
15+
let currentYear = new Date().getFullYear();
16+
ageOfb = currentYear - b.yearOfBirth
17+
}
18+
else {
19+
ageOfb = b.yearOfDeath - b.yearOfBirth
20+
}
21+
console.log(b.name + ": " + ageOfb)
22+
23+
return ageOfa < ageOfb ? 1 : -1
24+
})
25+
const oldest = sortByAge[0]
26+
console.log(oldest);
27+
return oldest;
328
};
429

530
// 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 yearOfDeath field is undefined on a non-oldest person', () => {
24+
test('finds the oldest person if yearOfDeath field is undefined on a non-oldest person', () => {
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 yearOfDeath field is undefined for the oldest person', () => {
43+
test('finds the oldest person if yearOfDeath field is undefined for the oldest person', () => {
4444
const people = [
4545
{
4646
name: "Carly",

0 commit comments

Comments
 (0)
0