Skip to content

Instantly share code, notes, and snippets.

@eengineergz
Created February 27, 2021 05:05
Show Gist options
  • Save eengineergz/61f130c8e0097572ed908fe2629bdee0 to your computer and use it in GitHub Desktop.
Save eengineergz/61f130c8e0097572ed908fe2629bdee0 to your computer and use it in GitHub Desktop.
let selectionSort = (arr) => {
let len = arr.length;
for (let i = 0; i < len; i++) {
let min = i;
for (let j = i + 1; j < len; j++) {
if (arr[min] > arr[j]) {
min = j;
}
}
if (min !== i) {
let tmp = arr[i];
arr[i] = arr[min];
arr[min] = tmp;
}
}
return arr;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment