Created
April 18, 2016 02:47
-
-
Save deptno/b6aa9e07267f3cc5bcebf6ee1c0f6454 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
#!/usr/bin/env node | |
function howOldAreYou(birth, employment, joinArmy, discharge) { | |
if (arguments.length !== 4) { | |
console.log(`arguments[yyyy-mm-dd]: 생일, 취업일, 입대, 전역`); | |
process.exit(); | |
} | |
var dateBirth = new Date(birth); | |
var dateEmployment = new Date(employment); | |
var dateJoinArmy = new Date(joinArmy); | |
var dateDischarge = new Date(discharge); | |
var interval = new Date(dateEmployment - dateBirth - (dateDischarge - dateJoinArmy)); | |
interval.setYear(interval.getYear() - 70); | |
return interval; | |
} | |
if (process.argv.indexOf(__filename) !== -1) { | |
var dateInterval = howOldAreYou.apply(null, process.argv.slice(2)); | |
console.log(`${dateInterval.getYear()}년 ${dateInterval.getMonth()}월 ${dateInterval.getDate()}일`); | |
} else { | |
module.exports = function howOldAreYou(birth, employment, joinArmy, discharge) { | |
return howOldAreYou.apply(null, arguments); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment