Last active
March 7, 2017 10:42
-
-
Save kevjose/279e291ea13c9f6d707930d70aa825fe to your computer and use it in GitHub Desktop.
Revisions
-
kevjose revised this gist
Mar 7, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -22,7 +22,7 @@ Array.prototype.selectSort = function(){ for(var i = 0; i < this.length; i++){ min = i; for(var j= i+1; j< this.length; j++){ if(this[j] < this[min]){ min = j; } } -
kevjose revised this gist
Mar 7, 2017 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -31,3 +31,8 @@ Array.prototype.selectSort = function(){ } } } var array = [9, 2, 5, 6, 4, 3, 7, 10, 1, 8]; array.bubbleSort(); console.log(array); -
kevjose created this gist
Mar 7, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,33 @@ Array.prototype.swap = function(i, j){ var temp = this[i]; this[i] = this[j]; this[j] = temp; } Array.prototype.bubbleSort = function(){ var swapped; do{ swapped = false; for(var i = 0; i < this.length; i++){ if(this[i] > this[i+1]){ this.swap(i, i+1); swapped = true; } } }while(swapped); } Array.prototype.selectSort = function(){ var min; for(var i = 0; i < this.length; i++){ min = i; for(var j= i+1; j< this.length; j++){ if(this[j] > this[min]){ min = j; } } if(min !== i){ this.swap(i, min) } } }