Skip to content

Instantly share code, notes, and snippets.

@atk atk/LICENSE.txt forked from 140bytes/LICENSE.txt
Last active Aug 29, 2015

Embed
What would you like to do?
Number is 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.