mirror of
https://github.com/10h30/odin-javascript-exercises.git
synced 2026-06-05 15:09:09 +09:00
Update files
This commit is contained in:
@@ -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");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user