Skip to content

Commit 5fa2fc2

Browse files
committed
execution of sorting algorithms is printed with dashed separators
1 parent a7d7f70 commit 5fa2fc2

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

algorithms/hanoi-towers.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
export default class Hanoi {
22

33
constructor(discs) {
4+
console.log('Running Hanoi Towers');
5+
46
this.towerA = discs;
57
this.towerB = [];
68
this.towerC = [];

sorting/index.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,18 @@ import SelectionSort from './selection-sort';
44
import MergeSort from './merge-sort';
55

66
const theArray = [72, 14, 34, 5, 24, 14, 53, 61, 38, 110, 39];
7-
let sortedArray;
87

9-
console.log(`original array: ${theArray}`);
10-
sortedArray = new BubbleSort().sort(theArray);
11-
console.log(`sorted array: ${sortedArray}`);
8+
const sortingAlgorithms = [
9+
BubbleSort,
10+
InsertionSort,
11+
SelectionSort,
12+
MergeSort
13+
];
1214

13-
console.log(`original array: ${theArray}`);
14-
sortedArray = new InsertionSort().sort(theArray);
15-
console.log(`sorted array: ${sortedArray}`);
16-
17-
console.log(`original array: ${theArray}`);
18-
sortedArray = new SelectionSort().sort(theArray);
19-
console.log(`sorted array: ${sortedArray}`);
20-
21-
console.log(`original array: ${theArray}`);
22-
sortedArray = new MergeSort().sort(theArray);
23-
console.log(`sorted array: ${sortedArray}`);
15+
sortingAlgorithms.forEach(algorithm => {
16+
console.log('-----------------------------------------');
17+
console.log(`original array: ${theArray}`);
18+
let sortedArray = new algorithm().sort(theArray);
19+
console.log(`sorted array: ${sortedArray}`);
20+
console.log('-----------------------------------------');
21+
});

0 commit comments

Comments
 (0)