Created
May 12, 2016 02:29
-
-
Save cbdavide/4e546d931c1322668bdf1849dfa8c33b to your computer and use it in GitHub Desktop.
Selection sort algorithm in javascript
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 characters
var selectionSort = function(array) { | |
var temp; | |
for(var i=0; i<array.length; i++){ | |
var mi = i; | |
for(var j = i + 1; j<array.length; j++) { | |
if(array[j] < array[mi]) | |
mi = j; | |
} | |
temp = array[i]; | |
array[i] = array[mi]; | |
array[mi] = temp; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment