completed final exercise
This commit is contained in:
parent
30ac06d409
commit
d538ffeb27
|
@ -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
|
||||
module.exports = findTheOldest;
|
||||
|
|
|
@ -21,7 +21,7 @@ describe('findTheOldest', () => {
|
|||
]
|
||||
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 = [
|
||||
{
|
||||
name: "Carly",
|
||||
|
@ -40,7 +40,7 @@ describe('findTheOldest', () => {
|
|||
]
|
||||
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 = [
|
||||
{
|
||||
name: "Carly",
|
||||
|
|
Loading…
Reference in New Issue