Created
January 5, 2015 02:53
-
-
Save omas/216d746c7b79ba44bea1 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
process.stdin.resume(); | |
process.stdin.setEncoding('utf8'); | |
process.stdin.on('data', function (chunk) { | |
//console.time('1'); | |
var lines = chunk.split('\n')[0].toString().split('/').join('-'); | |
var result = (function(date) { | |
var tmpYear = date.getFullYear(); | |
while (tmpYear === date.getFullYear() && !canDivide(date)) { | |
date.setDate(date.getDate() + 1); | |
} | |
return [ | |
date.getFullYear() | |
,('0' + (date.getMonth() + 1)).slice(-2) | |
,('0' + (date.getDate())).slice(-2) | |
].join('/'); | |
function canDivide(date) { | |
var y = date.getFullYear(); | |
var m = date.getMonth() + 1; | |
var d = date.getDate(); | |
return (y % (m * d) === 0); | |
} | |
}(new Date(lines))); | |
console.log(result); | |
//console.timeEnd('1'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment