Skip to content

Commit f1b5ab0

Browse files
committed
Solved Palindrome Number In JavaScript
1 parent ad107ee commit f1b5ab0

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

javascript/PalindromeNumber.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const isPalindrome = (x) => {
2+
if (x < 0 || (x % 10 === 0 && x !== 0)) {
3+
return false;
4+
}
5+
let result = x;
6+
let sum = 0;
7+
while (x !== 0) {
8+
let remainder = x % 10;
9+
sum = sum * 10 + remainder;
10+
x = Math.floor(x / 10);
11+
}
12+
if (sum === result) {
13+
return true;
14+
}
15+
return false;
16+
};

0 commit comments

Comments
 (0)