Ideas:
The idea is simple, add each bit of big data and record carry. It is important to note that the longer one of the two data needs to be processed separately, and at the end of the program, the highest-bit rounding is added.
Code:
functionsum (A, b) {varStra=a.tostring (), StrB=b.tostring (); varArra=stra.split (""). Reverse (), ARRB=strb.split (""). reverse (); varalen=Arra.length, Blen=arrb.length; if(alen==1| | Blen==1){ returnA +b; } varflag= 0,re=[],temp=0; varmaxlen=math.min (Alen,blen); for(vari=0;i<maxlen;i++) {Temp=parseint (Arra[i]) +parseint (Arrb[i]) +Flag; if(Temp > 9) {Re.push (temp-10); Flag= 1; } Else{Re.push (temp); Flag= 0; } } varClonearr=alen>blen?ARRA:ARRB; for(len=clonearr.length;i<len;i++) {Temp=parseint (Clonearr[i]) +Flag; if(Temp > 9) {Re.push (temp-10); Flag= 1; } Else{Re.push (temp); Flag= 0; } } if(flag) {Re.push (flag); } returnparseint (Re.reverse (). Join ("")); }
"Algorithm" Large integer Addition