Last active
March 27, 2018 13:37
-
-
Save rajasegar/122efe6206195502b13cbf231ae01524 to your computer and use it in GitHub Desktop.
This file contains 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 RETIREMENT_AGE = 65; | |
function calculateAge(birthday) { | |
let ageDifMs = Date.now() - birthday.getTime(); | |
let ageDate = new Date(ageDifMs); // miliseconds from epoch | |
return Math.abs(ageDate.getUTCFullYear() - 1970) | |
} | |
function calcRetirementTime(age) { | |
return RETIREMENT_AGE - age; | |
} | |
function timeToRetire(birthday) { // birthday is a date | |
let age = calculateAge(birthday); | |
let _timeToRetire = calcRetirementTime(age); | |
return _timeToRetire; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment