Skip to content

Instantly share code, notes, and snippets.

@ramzesucr
Created July 12, 2017 10:18
Show Gist options
  • Save ramzesucr/ead1b24a81834ec79672b8b1672599b2 to your computer and use it in GitHub Desktop.
Save ramzesucr/ead1b24a81834ec79672b8b1672599b2 to your computer and use it in GitHub Desktop.
Selection sort
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