test 12 completed
This commit is contained in:
parent
62ea370b94
commit
1fd8505b26
|
@ -1,5 +1,24 @@
|
||||||
const findTheOldest = function() {
|
const findTheOldest = function(people) {
|
||||||
|
let res;
|
||||||
|
let maxAge = 0;
|
||||||
|
let n = people.length;
|
||||||
|
for(let i = 0 ;i < n ; i++){
|
||||||
|
let birth = people[i].yearOfBirth;
|
||||||
|
let death;
|
||||||
|
if(people[i].yearOfDeath == undefined){
|
||||||
|
const d = new Date() ;
|
||||||
|
death = d.getFullYear();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
death = people[i].yearOfDeath;
|
||||||
|
}
|
||||||
|
let age = death - birth;
|
||||||
|
if(age > maxAge){
|
||||||
|
maxAge = age;
|
||||||
|
res = people[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Do not edit below this line
|
// Do not edit below this line
|
||||||
|
|
|
@ -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