Created
June 18, 2020 01:52
-
-
Save educartoons/b188d502853dc62dd51fd046ff859aed to your computer and use it in GitHub Desktop.
Implementation of Selection Sort in Typescript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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