-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.babel.js
86 lines (62 loc) · 1.65 KB
/
app.babel.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import chalk from 'chalk';
// Input Data
import incomeLevelsData from './income-levels.data';
console.log(chalk.cyan('Income Levels Data'));
console.log(incomeLevelsData);
// Table Row Space Definition
const tableRows = incomeLevelsData.map(item => item.borough);
console.log(chalk.cyan('Table Rows'));
console.log(tableRows);
// Table Column Space Definition
const tableColumns = [
'Borough Name',
null,
'2010 Census',
'2017 Estimate',
'% Change 2010 - 2017',
'2022 Projected',
'% Change 2017 - 2022',
];
console.log(chalk.cyan('Table Columns'));
console.log(tableColumns);
const percentChange = (past, present) => ((present - past) / past);
const table = {
rows: [],
};
incomeLevelsData.forEach((data) => {
const { borough } = data;
const avg = {
past: data[2010].avg,
present: data[2017].avg,
future: data[2022].avg,
};
const avgRow = Object.assign(avg, {
presentChange: percentChange(avg.past, avg.present),
futureChange: percentChange(avg.present, avg.future),
});
const med = {
past: data[2010].med,
present: data[2017].med,
future: data[2022].med,
};
const medRow = Object.assign(med, {
presentChange: percentChange(med.past, med.present),
futureChange: percentChange(med.present, med.future),
});
const boroughRows = [
{ label: 'Average', columns: avgRow },
{ label: 'Median', columns: medRow },
];
table.rows.push({
label: borough,
rows: boroughRows,
});
});
console.log(chalk.cyan('Table Object'));
console.log(table);
console.log(chalk.cyan('Size of Row Space'));
let space = 0;
table.rows.forEach((tr) => {
space += tr.rows.length;
});
console.log(space);