NumberIsPalindrome
Miniature checker if a number is a palindrome (http://en.wikipedia.org/wiki/Palindrome)
Miniature checker if a number is a palindrome (http://en.wikipedia.org/wiki/Palindrome)
function( | |
n // number | |
) { | |
n = (n + '').split(''); // coerce to string, split into array | |
return '' + n == n.reverse() // compare the joined array with a reversed version; | |
// string coercion is required to ensure we don't compare object references | |
// using a string on one side of the comparison coerces the other side to string, too. | |
} |
function(n){n=(n+'').split('');return''+n==n.reverse()} |
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
Version 2, December 2004 | |
Copyright (C) 2015 Alex Lohr (formerly Kloss) <alexthkloss@web.de> | |
Everyone is permitted to copy and distribute verbatim or modified | |
copies of this license document, and changing it is allowed as long | |
as the name is changed. | |
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | |
0. You just DO WHAT THE FUCK YOU WANT TO. |
{ | |
"name": "NumberIsPalindrome", | |
"description": "Checks whether a given number is a palindrome.", | |
"keywords": [ | |
"palindrome", | |
"number", | |
"math", | |
"euler" | |
] | |
} |
<!DOCTYPE html> | |
<title>numberIsPalindrome</title> | |
<div>Expected value: <b>true,true,false,false</b></div> | |
<div>Actual value: <b id="ret"></b></div> | |
<script> | |
// write a small example that shows off the API for your example | |
// and tests it in one fell swoop. | |
var numberIsPalindrome = function(n){n=(n+'').split('');return''+n==n.reverse()} | |
document.getElementById( "ret" ).innerHTML = [numberIsPalindrome(123321), numberIsPalindrome(123454321), | |
numberIsPalindrome(123123), numberIsPalindrome(11178111)] | |
</script> |