Created
March 14, 2016 23:45
-
-
Save jonathanbarton/c76a25c544dc813fc358 to your computer and use it in GitHub Desktop.
selection_sort_problem
This file contains 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
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