Skip to content

Instantly share code, notes, and snippets.

@emtiazahmed27
Last active July 1, 2022 00:06
Show Gist options
  • Save emtiazahmed27/f2999842fd5219c41d27fbdd48b6fe09 to your computer and use it in GitHub Desktop.
Save emtiazahmed27/f2999842fd5219c41d27fbdd48b6fe09 to your computer and use it in GitHub Desktop.
ICBatch05-FinalExam (Problem Solving)
//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