Last active
March 30, 2019 11:15
-
-
Save Sauloxd/c82b9de5a6a944ad6bd8396b7e341171 to your computer and use it in GitHub Desktop.
How old are you?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getDayMonthYear = (date) => ({ | |
day: date.getDate(), | |
month: date.getMonth(), | |
year: date.getFullYear() | |
}); | |
const pastBirthday = (birthday, today) => (today.month >= birthday.month) && (today.day >= birthday.day) | |
const age = (birthdayString) => { | |
const today = getDayMonthYear(new Date()); | |
const birthday = getDayMonthYear(new Date(birthdayString)); | |
return today.year - birthday.year + (pastBirthday(birthday, today) ? 0 : -1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment