File tree Expand file tree Collapse file tree 1 file changed +15
-16
lines changed
src/sorting/selectionsort Expand file tree Collapse file tree 1 file changed +15
-16
lines changed Original file line number Diff line number Diff line change 66 * @return {array } The sorted array
77 */
88function selectionSort ( array ) {
9- var min , idx , temp ;
10- for ( var i = 0 ; i < array . length ; i += 1 ) {
11- idx = i ;
12- min = array [ i ] ;
13- for ( var j = i + 1 ; j < array . length ; j += 1 ) {
14- if ( min > array [ j ] ) {
15- min = array [ j ] ;
16- idx = j ;
17- }
18- }
19- temp = array [ i ] ;
20- array [ i ] = min ;
21- array [ idx ] = temp ;
9+ var min , idx , temp ;
10+ for ( var i = 0 ; i < array . length ; i += 1 ) {
11+ idx = i ;
12+ min = array [ i ] ;
13+ for ( var j = i + 1 ; j < array . length ; j += 1 ) {
14+ if ( min > array [ j ] ) {
15+ min = array [ j ] ;
16+ idx = j ;
17+ }
2218 }
23- return array ;
24- }
25-
19+ temp = array [ i ] ;
20+ array [ i ] = min ;
21+ array [ idx ] = temp ;
22+ }
23+ return array ;
24+ }
You can’t perform that action at this time.
0 commit comments