JS超大整数相加
function sumBigNumber(a, b) {
var res = '',
temp = 0;
a = a.split('');
b = b.split('');
while (a.length || b.length || temp) {
temp += ~~a.pop() + ~~b.pop(); // ~~处理空数组pop结果undefined为0
res = (temp % 10) + res;
temp = temp > 9;
}
return res;
}
- Js 超大整数相加的解决方案
-
文章后面的正则会导致 '0' + '0' 为 '';问题
-