8000 add 'find the oldest' · NoderCoder/javascript-exercises@9fe4861 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9fe4861

Browse files
committed
add 'find the oldest'
1 parent 341661a commit 9fe4861

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

findTheOldest/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Find the Oldest
2+
3+
given an array of objects representing people with a birth and death year, return the oldest person.
4+
5+
## Hints
6+
- You should return the whole person object, but the tests mostly just check to make sure the name is correct.
7+
- this can be done with a couple of chained array methods, or by using `reduce`.
8+
- One of the tests checks for people with no death-date.. use JavaScript's Date function to get their age as of today.
9+

findTheOldest/findTheOldest.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
let findTheOldest = function() {
2+
3+
}
4+
5+
module.exports = findTheOldest

findTheOldest/findTheOldest.spec.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
let findTheOldest = require('./findTheOldest')
2+
3+
describe('findTheOldest', function() {
4+
it('finds the oldest person!', function() {
5+
const people = [
6+
{
7+
name: 'Carly',
8+
yearOfBirth: 1942,
9+
yearOfDeath: 1970,
10+
},
11+
{
12+
name: 'Ray',
13+
yearOfBirth: 1962,
14+
yearOfDeath: 2011
15+
},
16+
{
17+
name: 'Jane',
18+
yearOfBirth: 1912,
19+
yearOfDeath: 1941
20+
},
21+
]
22+
expect(findTheOldest(people).name).toEqual('Ray');
23+
});
24+
xit('finds the oldest person if someone is still living', function() {
25+
const people = [
26+
{
27+
name: 'Carly',
28+
yearOfBirth: 2018,
29+
},
30+
{
31+
name: 'Ray',
32+
yearOfBirth: 1962,
33+
yearOfDeath: 2011
34+
},
35+
{
36+
name: 'Jane',
37+
yearOfBirth: 1912,
38+
yearOfDeath: 1941
39+
},
40+
]
41+
expect(findTheOldest(people).name).toEqual('Ray');
42+
});
43+
xit('finds the oldest person if the OLDEST is still living', function() {
44+
const people = [
45+
{
46+
name: 'Carly',
47+
yearOfBirth: 1066,
48+
},
49+
{
50+
name: 'Ray',
51+
yearOfBirth: 1962,
52+
yearOfDeath: 2011
53+
},
54+
{
55+
name: 'Jane',
56+
yearOfBirth: 1912,
57+
yearOfDeath: 1941
58+
},
59+
]
60+
expect(findTheOldest(people).name).toEqual('Carly');
61+
});
62+
63+
});

0 commit comments

Comments
 (0)
0