We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent b94adb4 commit 95953f2Copy full SHA for 95953f2
1 file changed
chapter-5/1_selection_sort.ts
@@ -0,0 +1,16 @@
1
+function selectionSort(array: number[]): number[] {
2
+ for (let i = 0; i < array.length; i++) {
3
+ let lowestNumberIndex: number = i
4
+ for (let j = i + 1; j < array.length; j++) {
5
+ if (array[j] < array[lowestNumberIndex]) {
6
+ lowestNumberIndex = j
7
+ }
8
9
+ if (lowestNumberIndex != i) {
10
+ let temp: number = array[i]
11
+ array[i] = array[lowestNumberIndex]
12
+ array[lowestNumberIndex] = temp
13
14
15
+ return array
16
+}
0 commit comments