jumlah digit dalam jumlah javascript seluruh
sum = 0;
while (value) {
sum += value % 10;
value = Math.floor(value / 10);
}
Bloody Batfish
sum = 0;
while (value) {
sum += value % 10;
value = Math.floor(value / 10);
}
// 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