programming-examples/js/Math/Count the digits of an integer.js
2019-11-15 12:59:38 +01:00

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