Skip to content

Instantly share code, notes, and snippets.

@muhsalaa
Created October 4, 2020 08:45
Show Gist options
  • Save muhsalaa/a51e4a4df9488a1a618d810533ddc23c to your computer and use it in GitHub Desktop.
Save muhsalaa/a51e4a4df9488a1a618d810533ddc23c to your computer and use it in GitHub Desktop.
// with first convert to string
function isPalindrome(int) {
if (int < 0) return false
return +(''+int).split('').reverse().join('') === int
}
// without convert to string (bukan aku yang kerjain, this is brilliant)
function isPalindrome(int){
if(int<0) return false;
let reverse=0;
let num=int;
while(num>9)
{
reverse=reverse*10+num%10;
num=parseInt(num/10);
}
reverse=reverse*10+num;
return (int==reverse);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment