Remove trailing zeros from the sum of two numbers ( Using Stack ) | Function to remove trailing zeros from the sum of two numbers ; Stores the sum of A and B ; Stores the digits ; Stores the equivalent string of integer N ; Traverse the string ; Push the digit at i in the stack ; While top element is '0' ; Pop the top element ; Stores the resultant number without tailing 0 's ; While s is not empty ; Append top element of S in res ; Pop the top element of S ; Reverse the string res ; Input ; Function Call
function removeTailing ( A , B ) { let N = A + B ; let s = new Array ( ) ; let strsum = N . toString ( ) ; for ( let i = 0 ; i < strsum . length ; i ++ ) { s . push ( strsum . charAt ( i ) ) ; } while ( s [ s . length - 1 ] === ' ' ) { s . pop ( ) ; } let res = " " ; while ( s . length != 0 ) { res = res . concat ( s [ s . length - 1 ] ) ; s . pop ( ) ; } let str = " " ; str = str . concat ( res ) str = str . split ( " " ) . reverse ( ) . join ( " " ) ; return str . toString ( ) ; } let A = 130246 , B = 450164 ; document . write ( removeTailing ( A , B ) ) ;