Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Lines changed: 16 additions & 0 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /