test 12 completed

This commit is contained in:
rajroushan6714 2023-08-25 11:53:10 +05:30
parent 62ea370b94
commit 1fd8505b26
2 changed files with 23 additions and 4 deletions

View File

@ -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

View File

@ -21,7 +21,7 @@ describe('findTheOldest', () => {
]
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 = [
{
name: "Carly",
@ -40,7 +40,7 @@ describe('findTheOldest', () => {
]
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 = [
{
name: "Carly",