Skip to content

Instantly share code, notes, and snippets.

@jasonkarns
Created September 16, 2016 15:25
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 jasonkarns/062a32bc1aea304b208226c47b042e38 to your computer and use it in GitHub Desktop.
Save jasonkarns/062a32bc1aea304b208226c47b042e38 to your computer and use it in GitHub Desktop.
module.exports = function findMaxValidDate(min, max) {
var next = Math.floor((min+max)/2);
if(min == next) return min;
if(new Date(next) == "Invalid Date") {
return findMaxValidDate(min, next);
} else {
return findMaxValidDate(next, max);
}
}
console.log(module.exports(0, Number.MAX_VALUE));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment