Created
February 8, 2013 02:41
-
-
Save kruppel/4736198 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 | |
var limit = process.argv[2] | |
, palindromes = []; | |
if (!limit) { | |
console.error('Provide a limit!'); | |
process.exit(1); | |
} | |
function checkPalindrome(numstr) { | |
var isPalindrome = true; | |
for (var i = 0, len = numstr.length; i < len / 2; i++) { | |
if (numstr.charAt(i) !== numstr.charAt(len - i - 1)) { | |
isPalindrome = false; | |
break; | |
} | |
} | |
return isPalindrome; | |
} | |
for (var i = 1; i < limit; i++) { | |
if (checkPalindrome(i.toString())) { | |
palindromes.push(i); | |
} | |
} | |
console.log(palindromes.length); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment