Answers for "add digits of a number javascript"

1

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
0

js sum digits

// Sum of all the digits of a number in Javascript
const num = 1245,
    sum = num
        .toString()
        .split('')
        .map(Number)
        .reduce((a,b) => a + b);
console.log(sum); // 12
Posted by: Guest on January-24-2022

Code answers related to "add digits of a number javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language