Sorting the required segment
A = Array . prototype . concat ( A . slice ( 0 , i ) , A . slice ( i + 1 , j + 1 ) . sort ( ( a , b ) => a - b ) , A . slice ( j + 2 ) . sort ( ( a , b ) => a - b ) ) ; i = j ; }