Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript sum digits in string of numbers

const sumDigits = num => num.toString().split('').map(Number).reduce((a,b) => a + b);
//usage: mySum=sumDigits(myNum); console.log(sumDigits(1234)) output: 10
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #javascript #sum #digits #string #numbers
ADD COMMENT
Topic
Name
6+9 =