You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
15 lines
311 B
JavaScript
15 lines
311 B
JavaScript
5 years ago
|
function digits_count(n) {
|
||
|
var count = 0;
|
||
|
if (n > 1) ++count;
|
||
|
|
||
|
while (n / 10 >= 1) {
|
||
|
n /= 10;
|
||
|
++count;
|
||
|
}
|
||
|
|
||
|
return count;
|
||
|
}
|
||
|
|
||
|
console.log(digits_count(12112));
|
||
|
|
||
|
console.log(digits_count(457));
|