Created
July 12, 2017 10:18
-
-
Save ramzesucr/ead1b24a81834ec79672b8b1672599b2 to your computer and use it in GitHub Desktop.
Selection sort
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
const selectionSort = (input) => { | |
let data = input.slice() | |
for(var i = 0; i < data.length; i++) { | |
var lower = i | |
for(var j = i + 1; j < data.length; j++) { | |
if(data[lower] > data[j]) lower = j | |
} | |
exchange(data, i, lower) | |
} | |
return data; | |
} | |
const exchange = (list, left, right) => { | |
const mid = list[left] | |
list[left] = list[right] | |
list[right] = mid | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment