-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfp11.js
38 lines (31 loc) · 953 Bytes
/
fp11.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
const MEALS = [
{ description: 'Breakfast', calories: 460 },
{ description: 'Snack', calories: 180 },
{ description: 'Lunch', calories: 600 },
];
const { table, thead, tbody, tr, th, td } = tags;
const mealHeader = R.compose(
tr,
R.map(R.partial(th, [{ className: 'pa2 tl' }])),
);
const mealRow = R.curry((fields, row) =>
R.compose(
R.partial(tr, [{ className: 'stripe-dark' }]),
R.map(R.partial(td, [{ className: 'pa2' }])),
R.map(field => row[field]),
)(fields),
);
const mealsBody = R.curry((fields, rows) =>
R.compose(tbody, R.map(mealRow(fields)))(rows),
);
const mealsTable = R.curry((columns, fields, rows) =>
R.compose(
R.partial(table, [{ className: 'mw5 center w-100 collapse' }]),
R.append(R.__, [mealHeader(columns)]),
mealsBody(fields),
)(rows),
);
const node = document.getElementById('app');
node.appendChild(
mealsTable(['Meal', 'Calories'], ['description', 'calories'], MEALS),
);