Skip to content

Instantly share code, notes, and snippets.

@rajasegar
Last active March 27, 2018 13:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rajasegar/122efe6206195502b13cbf231ae01524 to your computer and use it in GitHub Desktop.
Save rajasegar/122efe6206195502b13cbf231ae01524 to your computer and use it in GitHub Desktop.
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