Skip to content

Commit e5b11c0

Browse files
committed
Added naive string search and selection sort algorithm
1 parent 0ac53fb commit e5b11c0

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

‎SortingAlgorithms/SelectionSort.js‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//Language: Javascript
2+
//Author: Uddesh Jain
3+
//Github: https://github.com/UddeshJain
4+
function selectionSort(arr) {
5+
for (let i = 0; i < arr.length; i++) {
6+
let lowest = i
7+
for (let j = i + 1; j < arr.length; j++) {
8+
if (arr[lowest] > arr[j]) {
9+
lowest = j
10+
}
11+
}
12+
if (lowest != i) {
13+
let temp = arr[lowest]
14+
arr[lowest] = arr[i]
15+
arr[i] = temp
16+
}
17+
}
18+
return arr
19+
}
20+
21+
console.log(selectionSort([64, 34, 8, 33, 1345, 76, 112, 30, 45]));

0 commit comments

Comments
 (0)