Skip to content

Instantly share code, notes, and snippets.

@koalicioous
Created August 8, 2023 22:48
Show Gist options
  • Save koalicioous/732f2fa07c11be013e1f3a3965eefbe2 to your computer and use it in GitHub Desktop.
Save koalicioous/732f2fa07c11be013e1f3a3965eefbe2 to your computer and use it in GitHub Desktop.
const selectionSort = (arr: number[]) => {
for (let i = 0; i < arr.length; i++) {
let minIndex = i
for (let j = i; j < arr.length; j++) {
if (arr[j] < arr[i]) minIndex = j
}
[arr[i], arr[minIndex]] = [arr[minIndex], arr[i]]
}
return arr
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment