Skip to content

Instantly share code, notes, and snippets.

@billykwok
Created January 16, 2016 23:44
Show Gist options
  • Save billykwok/20ee9790344e4057bffd to your computer and use it in GitHub Desktop.
Save billykwok/20ee9790344e4057bffd to your computer and use it in GitHub Desktop.
Selection Sort in ES6
function selectSort(array) {
for (let j = 0; j < array.length; ++j) {
let indexOfMin = j;
for (let i = j + 1; i < array.length; ++i) {
if (array[i] < array[indexOfMin]) indexOfMin = i;
}
[ array[j], array[indexOfMin] ] = [ array[indexOfMin], array[j] ];
}
return array;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment