Skip to content

Commit eb6677a

Browse files
authored
fix file formats (#884)
Co-authored-by: Thuvarakan Tharmarajasingam <thuva4.dev@gmail.com>
1 parent a7be3a0 commit eb6677a

File tree

11 files changed

+25
-34
lines changed

11 files changed

+25
-34
lines changed

algorithms/JavaScript/SelectionSort/selectionSort.js renamed to algorithms/JavaScript/SelectionSort/index.js

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,28 @@
1-
/* eslint-disable require-jsdoc */
21
/* eslint-disable max-len */
2+
/* eslint-disable require-jsdoc */
3+
// after each iternation you have 1 number in the correct positon
4+
// largest to smallest
5+
// O(n2) - worst case
6+
function selectionSortDescending(inputArray) {
7+
for (let i = 0; i < inputArray.length - 1; i++) {
8+
let maxIndex = i;
9+
for (let j = i + 1; j < inputArray.length; j++) {
10+
if (inputArray[maxIndex] < inputArray[j]) {
11+
maxIndex = j;// found new maximum
12+
}
13+
}
14+
15+
// swap if maximum isn't the current i iteration
16+
if (maxIndex != i) {
17+
const temp = inputArray[maxIndex];
18+
inputArray[maxIndex] = inputArray[i];
19+
inputArray[i] = temp;
20+
}
21+
console.log('In progress: ', inputArray);
22+
}
23+
return inputArray;
24+
}
25+
326
/* The selection sort algorithm sorts an array by repeatedly finding the minimum element
427
*(considering ascending order) from unsorted part and putting it at the beginning. The
528
*algorithm maintains two subarrays in a given array.
@@ -29,11 +52,5 @@ function selectionSort(items) {
2952
}
3053
}
3154

32-
// Implementation of bubbleSort
3355

34-
const ar = [5, 6, 7, 8, 1, 2, 12, 14];
35-
// Array before Sort
36-
console.log(ar);
37-
selectionSort(ar);
38-
// Array after sort
39-
console.log(ar);
56+
module.exports = {selectionSort, selectionSortDescending};

algorithms/JavaScript/SelectionSort/selectionSortDescending.js

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)