javascript

add sum of numbers of given numbers

Input - let a = 345;

let a = 345;
const sum = a.toString().split('').reduce((acc, curr) => {
    return acc + parseInt(curr);
}, 0);
console.log(sum); // Output: 12
Output
Output - 12
Was this helpful?