We can split at i if one of the following two is true . a ) All characters after str [ i ] are 0 b ) String after str [ i ] is divisible by b , i . e . , str [ i + 1. . n - 1 ] is divisible by b .
if ( rl [ i + 1 ] == 0 ) { document . write ( " " ) ; for ( let k = 0 ; k <= i ; k ++ ) document . write ( str [ k ] ) ; document . write ( " " ) ; for ( let k = i + 1 ; k < len ; k ++ ) document . write ( str [ k ] ) ; return ; } } document . write ( " " ) ; }