Skip to content

Instantly share code, notes, and snippets.

@educartoons
Created June 18, 2020 01:52
Show Gist options
  • Save educartoons/b188d502853dc62dd51fd046ff859aed to your computer and use it in GitHub Desktop.
Save educartoons/b188d502853dc62dd51fd046ff859aed to your computer and use it in GitHub Desktop.
Implementation of Selection Sort in Typescript
function selectionSort(A: number[]): number[] {
for (let i = 0; i < A.length - 1; i++) {
let min = i;
for (let j = i + 1; j < A.length; j++) {
if (A[j] < A[min]) {
min = j;
}
}
[A[min], A[i]] = [A[i], A[min]]
}
return A;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment