-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathsort.index.ts
31 lines (26 loc) · 878 Bytes
/
sort.index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { Algorithm } from './enum';
import { unixSort } from './sort';
const startTime = new Date().getTime();
let unique = false;
let algorithm;
for (let i = 0; i < process.argv.length; i++) {
const arg = process.argv[i];
// Represents if the output should contain unique elements
if (arg === '-u') {
unique = true;
}
if (arg === '--merge-sort') {
algorithm = Algorithm.MERGE_SORT;
} else if (arg === '--quick-sort') {
algorithm = Algorithm.QUICK_SORT;
} else if (arg === '--heap-sort') {
algorithm = Algorithm.HEAP_SORT;
} else if (arg === '--random-sort') {
algorithm = Algorithm.RANDOM_SORT;
}
}
const arr = unixSort(process.argv[2], unique, algorithm);
const output = arr.join('\n');
process.stdout.write(output);
const endTime = new Date().getTime();
process.stdout.write(`\n\nTotal Running time: ${endTime - startTime} ms\n`);