MCPcopy Create free account
hub / github.com/marijnh/Eloquent-JavaScript / activityTable

Function activityTable

code/solutions/11_2_real_promises.js:1–17  ·  view source on GitHub ↗
(day)

Source from the content-addressed store, hash-verified

1function activityTable(day) {
2 let table = [];
3 for (let i = 0; i < 24; i++) table[i] = 0;
4
5 return textFile("camera_logs.txt").then(files => {
6 return Promise.all(files.split("\n").map(name => {
7 return textFile(name).then(log => {
8 for (let timestamp of log.split("\n")) {
9 let date = new Date(Number(timestamp));
10 if (date.getDay() == day) {
11 table[date.getHours()]++;
12 }
13 }
14 });
15 }));
16 }).then(() => table);
17}
18
19activityTable(6)
20 .then(table => console.log(activityGraph(table)));

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected