-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
48 lines (42 loc) · 1.51 KB
/
index.js
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
'use strict'
const LogSource = require('./lib/log-source')
const Printer = require('./lib/printer')
// You can adjust this variable to see how your solutions perform under various "load"
const sourceCount = 100
/**
* Challenge Number 1!
*
* Assume that a LogSource only has one method: pop() which will return a LogEntry.
*
* A LogEntry is simply an object of the form:
* {
* date: Date,
* msg: String,
* }
*
* All LogEntries from a given LogSource are guaranteed to be popped in chronological order.
* Eventually a LogSource will end and return boolean false.
*
* Your job is simple: print the sorted merge of all LogEntries across `n` LogSources.
*
* Call `printer.print(logEntry)` to print each entry of the merged output as they are ready.
* This function will ensure that what you print is in fact in chronological order.
* Call 'printer.done()' at the end to get a few stats on your solution!
*/
const syncLogSources = []
for (let i = 0; i < sourceCount; i++) {
syncLogSources.push(new LogSource())
}
require('./solution/sync-sorted-merge')(syncLogSources, new Printer())
/**
* Challenge Number 2!
*
* Very similar to Challenge Number 1, except now you should assume that a LogSource
* has only one method: popAsync() which returns a promise that resolves with a LogEntry,
* or boolean false once the LogSource has ended.
*/
const asyncLogSources = []
for (let i = 0; i < sourceCount; i++) {
asyncLogSources.push(new LogSource())
}
require('./solution/async-sorted-merge')(asyncLogSources, new Printer())