Last active
July 1, 2022 00:06
-
-
Save emtiazahmed27/f2999842fd5219c41d27fbdd48b6fe09 to your computer and use it in GitHub Desktop.
ICBatch05-FinalExam (Problem Solving)
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
//write a function that checks whether an input is palindrome or not. | |
function check(input){ | |
if(isNaN(input)){ | |
const len = input.length; | |
for (let i = 0; i < len / 2; i++) { | |
if (input[i] !== input[len - 1 - i]) return false; | |
} | |
return true; | |
} | |
else { | |
let rem, temp, final = 0; | |
temp = input; | |
while(input>0){ | |
rem = input%10; | |
input = parseInt(input/10); | |
final = final*10+rem; | |
} | |
if(final==temp) return true; | |
else return false; | |
} | |
} | |
console.log(check("ABCDCBA")) | |
console.log(check(53135)); | |
console.log(check("Love You Vaai")); | |
//output: true | |
//output: true | |
//output: false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment