mirror of
https://github.com/10h30/odin-javascript-exercises.git
synced 2026-07-19 06:33:24 +09:00
Add solution directories for exercises
This commit is contained in:
@@ -0,0 +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;
|
||||
});
|
||||
};
|
||||
|
||||
const getAge = function (birth, death) {
|
||||
if (!death) {
|
||||
death = new Date().getFullYear();
|
||||
}
|
||||
return death - birth;
|
||||
};
|
||||
|
||||
module.exports = findTheOldest;
|
||||
Reference in New Issue
Block a user