Passed all remaining tests in exercise 12
This commit is contained in:
parent
2d76b4cb78
commit
3faa9634ab
|
@ -1,7 +1,8 @@
|
||||||
const findTheOldest = function(array) {
|
const findTheOldest = function(array) {
|
||||||
const oldest = array.sort((a, b) => {
|
const oldest = array.sort((a, b) => {
|
||||||
let ageA = a.yearOfDeath - a.yearOfBirth;
|
let yearNow = (new Date()).getFullYear();
|
||||||
let ageB = b.yearOfDeath - b.yearOfBirth;
|
let ageA = ((a.yearOfDeath) ? a.yearOfDeath : yearNow) - a.yearOfBirth;
|
||||||
|
let ageB = ((b.yearOfDeath) ? b.yearOfDeath : yearNow) - b.yearOfBirth;
|
||||||
return (ageA > ageB) ? -1 : 1;
|
return (ageA > ageB) ? -1 : 1;
|
||||||
})[0];
|
})[0];
|
||||||
return oldest;
|
return oldest;
|
||||||
|
|
|
@ -21,7 +21,7 @@ describe('findTheOldest', () => {
|
||||||
]
|
]
|
||||||
expect(findTheOldest(people).name).toBe('Ray');
|
expect(findTheOldest(people).name).toBe('Ray');
|
||||||
});
|
});
|
||||||
test.skip('finds the person with the greatest age if someone is still living', () => {
|
test('finds the person with the greatest age 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 person with the greatest age if the OLDEST is still living', () => {
|
test('finds the person with the greatest age if the OLDEST is still living', () => {
|
||||||
const people = [
|
const people = [
|
||||||
{
|
{
|
||||||
name: "Carly",
|
name: "Carly",
|
||||||
|
|
Loading…
Reference in New Issue