FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaScript/Maths/NumberOfDigits.js at master · MMABSOUT/JavaScript · GitHub
MMABSOUT
/
JavaScript
Public
forked from
TheAlgorithms/JavaScript
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaScript
/
Maths
/
NumberOfDigits.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
23 lines (20 loc) · 654 Bytes
Breadcrumbs
JavaScript
/
Maths
/
NumberOfDigits.js
Copy path
File metadata and controls
23 lines (20 loc) · 654 Bytes
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
/**
*
* Author: dephraiim
* License: GPL-3.0 or later
*
* Returns the number of digits of a given integer
*
*/
const
numberOfDigit
=
(
n
)
=>
Math
.
abs
(
n
)
.
toString
(
)
.
length
/**
* Returns the number of digits of a given integer.
*
*
@param
{
number
} n - The integer for which to count digits.
*
@returns
{
number
} The number of digits in the integer.
*
@see
https://math.stackexchange.com/questions/2145480/how-does-the-logarithm-returns-the-number-of-digits-of-a-number
*
@author
dev-madhurendra
*/
const
numberOfDigitsUsingLog
=
(
n
)
=>
n
===
0
?
1
:
Math
.
floor
(
Math
.
log10
(
Math
.
abs
(
n
)
)
)
+
1
export
{
numberOfDigit
,
numberOfDigitsUsingLog
}
Back
|
FazBrowse Home
|
New Git URL