substring
is required?
Or can you do something like this?
function sum(num) {
var str = String(num);
var numbers;
var total = 0;
for (var i = 0; i < str.length; i++) {
total += parseInt(str[i]);
if (i == 0) {
numbers = str[i]
} else {
numbers += " + " + str[i]
}
}
return total + " = " + numbers
}
t = sum("2231");
console.log(t)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…