Skip to content

Commit fc484a9

Browse files
committed
Add license
1 parent 7e47c47 commit fc484a9

File tree

16 files changed

+466
-0
lines changed

16 files changed

+466
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
'use strict';
2+
3+
// FP paradigm:
4+
// 1. Equations instead of control flow
5+
// 2. Lazy calculations
6+
// 3. Parallel execution ready
7+
// 4. Recursion instead of loops
8+
// 5. Immutability, no state
9+
// 6. No variables, no side effects
10+
// 7. Math model
11+
12+
const fs = require('fs');
13+
14+
const proportion = (max, val) => Math.round(val * 100 / max);
15+
const compose = (...funcs) => x => funcs.reduce((x, fn) => fn(x), x);
16+
17+
const cellPad = (i, s, width) => (i ? s.padStart(width) : s.padEnd(width));
18+
const cellWidth = i => [18, 10, 8, 8, 18, 6][i];
19+
20+
const renderCell = (cell, i) => cellPad(i, cell + '', cellWidth(i));
21+
const renderRow = row => row.map(renderCell).join('');
22+
const renderTable = table => table.map(renderRow).join('\n');
23+
24+
const densityCol = () => 3
25+
const sortByDensity = table => table.sort(
26+
(row1, row2) => (row2[densityCol()] - row1[densityCol()])
27+
)
28+
const calcColumn = (table, max) => table.map(
29+
row => (row.push(proportion(max, row[densityCol()])), row)
30+
);
31+
const calcProportion = table => calcColumn(table, table[0][densityCol()]);
32+
33+
const parseTable = lines => lines.map(line => line.split(','));
34+
const toLines = data => data.split('\n').filter((s, i) => i && s);
35+
const readFile = file => fs.readFileSync(file).toString();
36+
const getDataset = compose(readFile, toLines, parseTable);
37+
38+
const main = compose(getDataset, sortByDensity, calcProportion, renderTable);
39+
40+
console.log(main('./cities.dat'));

JavaScript/!!!!/4-oop.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict';
2+
3+
const

JavaScript/!!!!/5-functor.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict';
2+
3+
const

JavaScript/!!!!/6-asynchronous.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict';
2+
3+
const

JavaScript/!!!!/7-dsl.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict';
2+
3+
const

JavaScript/!!!!/8-event.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict';
2+
3+
const

JavaScript/!!!!/9-reactive.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict';
2+
3+
const

JavaScript/!!!!/a.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const = (α, β, γ) => (α + β + γ);
2+
const = (α, γ) => (α, 10, γ);
3+
console.log((2, 3));
4+
5+
const расстрелять = '🔫';
6+
console.log(расстрелять);

JavaScript/!!!!/compose.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const compose = (...funcs) => x => funcs.reduce((x, fn) => fn(x), x);
2+
3+
const inc = x => ++x;
4+
const square = x => x * x;
5+
const f = compose(inc, square);
6+
7+
console.log(f(5));

JavaScript/!!!!/const.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
'use strict';
2+
3+
con { , 𝕊 } = require('mathtypes');
4+
5+
const util = require('util');
6+
7+
const = (x) => {
8+
if (typeof(x) !== 'number') {
9+
throw new TypeError('Дыбилыбилять, это что, натуральное число?');
10+
}
11+
const = () => x;
12+
const methods = {
13+
is: value => value.name === 'ℕ',
14+
get type() {
15+
return .name;
16+
},
17+
[util.inspect.custom]: () => x
18+
};
19+
return Object.assign(, methods);
20+
};
21+
22+
const 𝕊 = (x) => {
23+
if (typeof(x) !== 'string') {
24+
throw new TypeError('Дыбилыбилять, строка что такое, знаешь?');
25+
}
26+
const 𝕊 = () => x;
27+
const methods = {
28+
is: value => value.name === '𝕊',
29+
get type() {
30+
return 𝕊.name;
31+
},
32+
[util.inspect.custom]: () => x
33+
};
34+
return Object.assign(𝕊, methods);
35+
};
36+
37+
const sum = (a, b) => (a) + (b);
38+
39+
const a = (5);
40+
41+
console.log('a.type === ' + a.type);
42+
43+
const = {
44+
name: 𝕊('Marcus Aurelius'),
45+
city: 𝕊('Rome'),
46+
born: (121)
47+
};
48+
49+
console.log({});
50+
console.log(.name);
51+
console.log(.name + ' from ' + .city);

0 commit comments

Comments
 (0)