add 'find the oldest'

This commit is contained in:
Cody Loyd 2019-04-11 12:00:21 -05:00
parent 341661a100
commit 9fe4861756
3 changed files with 77 additions and 0 deletions

9
findTheOldest/README.md Normal file
View File

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

View File

@ -0,0 +1,5 @@
let findTheOldest = function() {
}
module.exports = findTheOldest

View File

@ -0,0 +1,63 @@
let findTheOldest = require('./findTheOldest')
describe('findTheOldest', function() {
it('finds the oldest person!', function() {
const people = [
{
name: 'Carly',
yearOfBirth: 1942,
yearOfDeath: 1970,
},
{
name: 'Ray',
yearOfBirth: 1962,
yearOfDeath: 2011
},
{
name: 'Jane',
yearOfBirth: 1912,
yearOfDeath: 1941
},
]
expect(findTheOldest(people).name).toEqual('Ray');
});
xit('finds the oldest person if someone is still living', function() {
const people = [
{
name: 'Carly',
yearOfBirth: 2018,
},
{
name: 'Ray',
yearOfBirth: 1962,
yearOfDeath: 2011
},
{
name: 'Jane',
yearOfBirth: 1912,
yearOfDeath: 1941
},
]
expect(findTheOldest(people).name).toEqual('Ray');
});
xit('finds the oldest person if the OLDEST is still living', function() {
const people = [
{
name: 'Carly',
yearOfBirth: 1066,
},
{
name: 'Ray',
yearOfBirth: 1962,
yearOfDeath: 2011
},
{
name: 'Jane',
yearOfBirth: 1912,
yearOfDeath: 1941
},
]
expect(findTheOldest(people).name).toEqual('Carly');
});
});