peterschussheim
10/1/2016 - 3:54 PM

Separate an integer into an array of digits. Test

Separate an integer into an array of digits. Test

function addTwoDigits(n) {
  var arr = n.toString(10).split("").map(function(t) {
    return parseInt(t);
  });
  
  var sum = arr.reduce(function(a, b) {
    return a + b;
  });
  
  return sum;
}
  
  
  
var n = 123456789;
console.log(addTwoDigits(n)); // 45