GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitFun/isNumberPalindrome.js at master · kennyle37/GitFun

Expand file tree

/

isNumberPalindrome.js

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
56 lines (53 loc) · 1.41 KB
/

isNumberPalindrome.js

Copy path

File metadata and controls

56 lines (53 loc) · 1.41 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
Make a copy of the original input and assign units digit using modulo and place in reversed version
until done, compare the reversed number with the original. If equal, return true.
Steps
1
Copy the input 1331
digit = 1331 % 10 = 1
reversed number = 1
number copy = 133
2
digit = 133 % 10 = 3
reversed number = 13
number copy = 13
3
digit = 13 % 10 = 3
reversed number = 133
number copy = 1
4
digit = 1 % 10 = 1
reversed number = 1331
number copy = 0
5
1331 = 1331 return true
const isNumberPalindrome = (number) => {
// copy input number to build reversed number
// init reversed number and digit
// iterate until copy is 0 or less
// current digit is copy % 10
// multiply reversed number by 10 and add the digit
// divide the number copy by 10 and remove decimals
}
return reversed === number;
}
*/
const isNumberPalindrome = (number) => {
// copy input number to build reversed number
let numCopy = number;
// init reversed number and digit
let reversed = 0;
let digit = 0;
// iterate until copy is 0 or less
while(numCopy > 0){
// current digit is copy % 10
digit = numCopy % 10
// multiply reversed number by 10 and add the digit
reversed = (reversed * 10) + digit;
// divide the number copy by 10 and remove decimals
numCopy = Math.floor(numCopy / 10);
console.log(numCopy);
}
return reversed === number;
}
isNumberPalindrome(1331);
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.