Created
October 25, 2012 06:46
-
-
Save island205/3950902 to your computer and use it in GitHub Desktop.
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
| selectionSort = (arr)-> | |
| for i in [0...arr.length - 1] | |
| min = arr[i] | |
| minI = i | |
| for j in [i+1...arr.length] | |
| if min > arr[j] | |
| minI = j | |
| if i isnt minI | |
| temp = arr[i] | |
| arr[i] = arr[minI] | |
| arr[minI] = temp | |
| arr | |
| #test | |
| console.log selectionSort [1,2,3,3,4,6, 9, 2, 1] | |
| console.log selectionSort [1] | |
| console.log selectionSort [0] | |
| console.log selectionSort [1,0] | |
| console.log selectionSort [1,0,1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment