completed final exercise

This commit is contained in:
Roberra0 2023-07-07 19:15:27 -07:00
parent 30ac06d409
commit d538ffeb27
2 changed files with 17 additions and 5 deletions

View File

@ -1,6 +1,18 @@
const findTheOldest = function() { const findTheOldest = function(people){
peopleSorted = people.sort((a, b)=>
(getAge(a) > getAge(b)) ?
-1:
1
);
return(peopleSorted[0]);
}
function getAge(person){
let death = person.yearOfDeath;
if(!death){
death = new Date().getFullYear();
}; };
return death - person.yearOfBirth;
}
// Do not edit below this line // Do not edit below this line
module.exports = findTheOldest; module.exports = findTheOldest;

View File

@ -21,7 +21,7 @@ describe('findTheOldest', () => {
] ]
expect(findTheOldest(people).name).toBe('Ray'); expect(findTheOldest(people).name).toBe('Ray');
}); });
test.skip('finds the oldest person if someone is still living', () => { test('finds the oldest person 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 oldest person if the OLDEST is still living', () => { test('finds the oldest person if the OLDEST is still living', () => {
const people = [ const people = [
{ {
name: "Carly", name: "Carly",