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.
programming-examples/js/Math/Count the digits of an inte...

15 lines
311 B
JavaScript

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));