Here you can find the source of selectionSort()
Array.prototype.selectionSort = function () { for (var i = 0; i < this.length; i++) { var index = i; for (var j = i+1; j < this.length; j++) { if(this[j] < this[index]){ index = j;//from ww w . j a v a2 s.c om } } this.swap(i, index); } };
Array.prototype.selectionSort = function () { var i, j, min; var temp; for (i = 0; i < this.length - 1; i++) { min = i; for (j = i + 1; j < this.length; j++) { if (this[min] > this[j]) { min = j; temp = this[min]; this[min] = this[i]; this[i] = temp; };
Array.prototype.selectionSort = function () { 'use strict'; var lastIndex = this.length, temp, i, j, smaller; for( i = 0 ; i < lastIndex ; i++){ smaller = i; ...
Array.prototype.selectionSort=function(){ var sorted=[]; while(this.length){ var minIndex=0; for(var i=0; i<=this.length;i++) { if (this[i] < this[minIndex]) { minIndex = i; sorted.push(this[minIndex]); this.splice(minIndex,1); this.push(sorted); }; var numbers=[4, 1, 1, 4, 2, 3, 4, 4, 1, 2, 4, 9, 3 ]; numbers.selectionSort(); console.log('numbers=[4, 1, 1, 4, 2, 3, 4, 4, 1, 2, 4, 9, 3 ];'); console.log(numbers.join(', '));
Array.prototype.selectionSort = function(){ var sorted = []; while(this.length) { var minInd = 0; for (var ind = 0; ind < this.length; ind++) { if(this[ind] < this[minInd]) minInd = ind; sorted.push(this[minInd]); this.splice(minInd, 1); ...
Array.prototype.selectionSort = function() { var sorted_array = []; var temp_array = this; var counter = 0; var arrEnd = this.length; while(counter < arrEnd) { var index = temp_array.indexOf(temp_array.min()); var x = parseInt(temp_array.splice([index], 1).join('')) console.log(x); ...