Update files

This commit is contained in:
thatblindgeye
2023-01-21 12:53:41 -05:00
parent fb1a2db8d7
commit 4a112362c8
31 changed files with 571 additions and 449 deletions
@@ -1,19 +1,19 @@
const findTheOldest = function (array) {
return array.reduce((oldest, currentPerson) => {
const oldestAge = getAge(oldest.yearOfBirth, oldest.yearOfDeath);
const currentAge = getAge(
currentPerson.yearOfBirth,
currentPerson.yearOfDeath
);
return oldestAge < currentAge ? currentPerson : oldest;
});
return array.reduce((oldest, currentPerson) => {
const oldestAge = getAge(oldest.yearOfBirth, oldest.yearOfDeath);
const currentAge = getAge(
currentPerson.yearOfBirth,
currentPerson.yearOfDeath
);
return oldestAge < currentAge ? currentPerson : oldest;
});
};
const getAge = function (birth, death) {
if (!death) {
death = new Date().getFullYear();
}
return death - birth;
if (!death) {
death = new Date().getFullYear();
}
return death - birth;
};
module.exports = findTheOldest;
@@ -1,62 +1,62 @@
const findTheOldest = require('./findTheOldest-solution');
const findTheOldest = require("./findTheOldest");
describe('findTheOldest', () => {
test('finds the oldest person!', () => {
const people = [
{
name: 'Carly',
yearOfBirth: 1942,
yearOfDeath: 1970,
},
{
name: 'Ray',
yearOfBirth: 1962,
yearOfDeath: 2011,
},
{
name: 'Jane',
yearOfBirth: 1912,
yearOfDeath: 1941,
},
];
expect(findTheOldest(people).name).toBe('Ray');
});
test.skip('finds the oldest person if someone is still living', () => {
const people = [
{
name: 'Carly',
yearOfBirth: 2018,
},
{
name: 'Ray',
yearOfBirth: 1962,
yearOfDeath: 2011,
},
{
name: 'Jane',
yearOfBirth: 1912,
yearOfDeath: 1941,
},
];
expect(findTheOldest(people).name).toBe('Ray');
});
test.skip('finds the oldest person if the OLDEST is still living', () => {
const people = [
{
name: 'Carly',
yearOfBirth: 1066,
},
{
name: 'Ray',
yearOfBirth: 1962,
yearOfDeath: 2011,
},
{
name: 'Jane',
yearOfBirth: 1912,
yearOfDeath: 1941,
},
];
expect(findTheOldest(people).name).toBe('Carly');
});
describe("findTheOldest", () => {
test("finds the oldest person!", () => {
const people = [
{
name: "Carly",
yearOfBirth: 1942,
yearOfDeath: 1970,
},
{
name: "Ray",
yearOfBirth: 1962,
yearOfDeath: 2011,
},
{
name: "Jane",
yearOfBirth: 1912,
yearOfDeath: 1941,
},
];
expect(findTheOldest(people).name).toBe("Ray");
});
test.skip("finds the oldest person if someone is still living", () => {
const people = [
{
name: "Carly",
yearOfBirth: 2018,
},
{
name: "Ray",
yearOfBirth: 1962,
yearOfDeath: 2011,
},
{
name: "Jane",
yearOfBirth: 1912,
yearOfDeath: 1941,
},
];
expect(findTheOldest(people).name).toBe("Ray");
});
test.skip("finds the oldest person if the OLDEST is still living", () => {
const people = [
{
name: "Carly",
yearOfBirth: 1066,
},
{
name: "Ray",
yearOfBirth: 1962,
yearOfDeath: 2011,
},
{
name: "Jane",
yearOfBirth: 1912,
yearOfDeath: 1941,
},
];
expect(findTheOldest(people).name).toBe("Carly");
});
});