jaimex8
1/27/2016 - 5:23 AM

Sum of digits (map function)

Sum of digits (map function)

function digitSum(n) {
    var arr = n.toString().split('').map(function(i){ return parseInt(i)});

    console.log(arr);
    return arr.reduce(function(sum, curr){
    	return sum + curr;
    })
}