Skip to content

Instantly share code, notes, and snippets.

@kruppel
Created February 8, 2013 02:41
Show Gist options
  • Save kruppel/4736198 to your computer and use it in GitHub Desktop.
Save kruppel/4736198 to your computer and use it in GitHub Desktop.
#!/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