Created
October 4, 2020 08:45
-
-
Save muhsalaa/a51e4a4df9488a1a618d810533ddc23c to your computer and use it in GitHub Desktop.
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
// 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