Created
January 26, 2017 04:28
-
-
Save scottshane/66561af97ff42e1d526d8fe8a8a44fa5 to your computer and use it in GitHub Desktop.
next smallest numeric palindrome
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
function processNum(num) { | |
var _num = num + ""; | |
var _left; | |
var _right; | |
var _palin; | |
if (_num.length % 2 === 0) { | |
_left = (~~(_num.substr(0, _num.length/2))+1).toString().split(''); | |
_palin = (~~_left.concat(_left.slice(0).reverse()).join('')); | |
} else { | |
_left = (~~(_num.substr(0, _num.length/2))+1).toString().split(''); | |
_right = (~~(_num.substr(_left.length,1))).toString().split(''); | |
_palin = _left.concat(_right).concat(_left.slice(0).reverse()).join(''); | |
console.log(_right, _left) | |
console.log(_palin) | |
} | |
return _palin; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment