Skip to content

Instantly share code, notes, and snippets.

@jonathanbarton
Created March 14, 2016 23:45
Show Gist options
  • Save jonathanbarton/c76a25c544dc813fc358 to your computer and use it in GitHub Desktop.
Save jonathanbarton/c76a25c544dc813fc358 to your computer and use it in GitHub Desktop.
selection_sort_problem
function selectionSort(arr, currentMin) {
while(currentMin === undefined || currentMin < arr.length) {
currentMin = currentMin || 0;
for(var i = currentMin; i < arr.length; i++){
if(arr[currentMin] > arr[i]){
var a=arr[currentMin],b=arr[i];
b = [a, a = b][0];
arr[currentMin] = a;
arr[i] = b;
}
}
currentMin += 1;
}
console.log(arr);
}
selectionSort([3,4,2,1,5]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment