Gnome Sort | A function to sort the algorithm using gnome sort ; Driver Code
function gnomeSort ( arr , n ) { let index = 0 ; while ( index < n ) { if ( index == 0 ) index ++ ; if ( arr [ index ] >= arr [ index - 1 ] ) index ++ ; else { let temp = 0 ; temp = arr [ index ] ; arr [ index ] = arr [ index - 1 ] ; arr [ index - 1 ] = temp ; index -- ; } } return ; } let arr = [ 34 , 2 , 10 , - 9 ] ; gnomeSort ( arr , arr . length ) ; document . write ( " " ) ; document . write ( arr . toString ( ) ) ;