Since we want the smallest next value , shift all 1 ' s ▁ at ▁ the ▁ end ▁ in ▁ the ▁ binary ▁ ▁ substring ▁ starting ▁ from ▁ index ▁ ' i + 2 '
let j = i + 2 , k = l - 1 ; while ( j < k ) { if ( bnum [ j ] == ' ' && bnum [ k ] == ' ' ) { let ch = bnum [ j ] ; bnum [ j ] = bnum [ k ] ; bnum [ k ] = ch ; j ++ ; k -- ; }