Skip to content

Commit f58d51b

Browse files
committed
Improve functional example
1 parent d755b30 commit f58d51b

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

JavaScript/2-functional-good.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,14 @@ const renderCell = (cell, i) => cellPad(i, cell + '', cellWidth(i));
2121
const renderRow = row => row.map(renderCell).join('');
2222
const renderTable = table => table.map(renderRow).join('\n');
2323

24-
// const densityCol = () => 3;
25-
const densityCol = 3;
24+
const densityCol = () => 3;
2625
const sortByDensity = table => table.sort(
27-
(row1, row2) => (row2[densityCol] - row1[densityCol])
26+
(row1, row2) => (row2[densityCol()] - row1[densityCol()])
2827
);
2928
const calcColumn = (table, max) => table.map(
30-
row => (row.push(proportion(max, row[densityCol])), row)
29+
row => (row.push(proportion(max, row[densityCol()])), row)
3130
);
32-
const calcProportion = table => calcColumn(table, table[0][densityCol]);
31+
const calcProportion = table => calcColumn(table, table[0][densityCol()]);
3332

3433
const parseTable = lines => lines.map(line => line.split(','));
3534
const toLines = data => data.split('\n').filter((s, i) => i && s);

0 commit comments

Comments
 (0)