Function to find next gap .
function nextGap ( gap ) { if ( gap <= 1 ) return 0 ; return parseInt ( gap / 2 , 10 ) + ( gap % 2 ) ; } function merge ( arr1 , arr2 , n , m ) { let i , j , gap = n + m ; for ( gap = nextGap ( gap ) ; gap > 0 ; gap = nextGap ( gap ) ) {