-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathmain.js
32 lines (27 loc) · 1 KB
/
main.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
var fs = require('fs');
function fetchFromFile(stream) {
return new Promise((resolve, reject) => {
fs.readFile(stream, 'utf-8', (err, data) => {
if(err) reject(err);
resolve(JSON.parse(data));
})
});
}
// If you want to have the timestamps of the event as a Date object rather than a string, enable this
// transformation. This transformation mutates the events. After the transformation, the timestamp is a Date
// Also see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date for more info.
function transformTimestampToDate(events) {
return events.map(event => {
event.timestamp = new Date(event.timestamp);
return event;
});
}
var fileName = process.argv[2];
fetchFromFile(fileName)
.then(events => transformTimestampToDate(events))
.then(events => console.log(eventCounter(events)))
.catch(error => console.log(error))
// Write your projection here
function eventCounter(events) {
return events.reduce((acc, event) => acc + 1, 0);
}