Skip to content

Instantly share code, notes, and snippets.

@ramsunvtech
Last active January 19, 2016 08:54
Show Gist options
  • Save ramsunvtech/6cbeeeca09bedc26ba35 to your computer and use it in GitHub Desktop.
Save ramsunvtech/6cbeeeca09bedc26ba35 to your computer and use it in GitHub Desktop.
Selection Sort in Javascript
function selectionSort(arr){
var minIdx, temp,
len = arr.length;
for(var i = 0; i < len; i++){
minIdx = i;
for(var j = i+1; j<len; j++){
if(arr[j]<arr[minIdx]){
minIdx = j;
}
}
temp = arr[i];
arr[i] = arr[minIdx];
arr[minIdx] = temp;
}
return arr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment