Skip to content

Instantly share code, notes, and snippets.

@cbdavide
Created May 12, 2016 02:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cbdavide/4e546d931c1322668bdf1849dfa8c33b to your computer and use it in GitHub Desktop.
Save cbdavide/4e546d931c1322668bdf1849dfa8c33b to your computer and use it in GitHub Desktop.
Selection sort algorithm in javascript
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