Answers for "js calculates the digit sum of an integer"

9

count the total number of digits of a number in javascript

const count = n => String((Math.abs(n))).length;

count(123); // ➞ 3
count(-45678); // ➞ 5
count(8912); // ➞ 4
Posted by: Guest on April-22-2021
3

sum of digits in a whole number javascript

sum = 0;
while (value) {
    sum += value % 10;
    value = Math.floor(value / 10);
}
Posted by: Guest on August-26-2021

Code answers related to "js calculates the digit sum of an integer"

Code answers related to "Javascript"

Browse Popular Code Answers by Language