Skip to content

Commit e3dfe8c

Browse files
committed
Syntax and code style
1 parent 4c2e5b0 commit e3dfe8c

3 files changed

Lines changed: 24 additions & 20 deletions

File tree

JavaScript/1-superposition.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
let pow = Math.pow;
44
let sqrt = Math.sqrt;
5-
let inc = x => ++x;
5+
let inc = x => x + 1;
66
let add = (a, b) => a + b;
77
let mul = (a, b) => a * b;
88
let div = (a, b) => a / b;

JavaScript/2-composition.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
let compose = (f1, f2) => (x) => f2(f1(x));
3+
let compose = (f1, f2) => x => f2(f1(x));
44

55
let s = 'MARCUS AURELIUS';
66
console.log(s);

JavaScript/composeAsync.js

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,39 @@
1+
'use strict';
2+
13
global.api = {};
24
api.fs = require('fs');
35

46
let reduceAsync = function(items, performer, callback, initialValue) {
5-
var nseted = (typeof initialValue === 'undefined'),
6-
counter = nseted ? 1 : 0,
7-
previous = nseted ? items[0] : initialValue,
8-
current = nseted ? items[1] : items[0];
7+
var nseted = (typeof(initialValue) === 'undefined'),
8+
counter = nseted ? 1 : 0,
9+
previous = nseted ? items[0] : initialValue,
10+
current = nseted ? items[1] : items[0];
911

1012
function response(err, data) {
1113
if (!err && counter !== items.length - 1) {
1214
++counter;
1315
previous = data;
1416
current = items[counter];
1517
performer(previous, current, response, counter, items);
16-
}
17-
else {
18-
if (callback) callback(err, data);
18+
} else if (callback) {
19+
callback(err, data);
1920
}
2021
}
2122

2223
performer(previous, current, response, counter, items);
23-
}
24+
};
2425

2526
// params - array of parametrs for functions
2627
// args - array of functions
2728
// args[i] - function
2829
// args[-1] - callback(err, data)
30+
//
2931
function composeAsync(params, ...args) {
3032
reduceAsync(
3133
args.slice(0, -1),
32-
(params, fn, callback) => fn.apply(null, [].concat(params).concat(callback)),
34+
(params, fn, callback) => fn.apply(
35+
null, [].concat(params).concat(callback)
36+
),
3337
args[args.length - 1],
3438
params
3539
);
@@ -50,20 +54,20 @@ function wrapAsync(callback) {
5054
}
5155

5256
function read(file, charset, callback) {
53-
console.dir({read:{file, callback}});
57+
console.dir({ read: { file, callback } });
5458
api.fs.readFile(file, charset, callback);
5559
}
5660

5761
function parse(data, callback) {
58-
console.dir({parse:{data, callback}});
59-
wrapAsync(() => {
60-
callback(null, ['Data has been', 'processed!']);
61-
});
62+
console.dir({ parse: { data, callback } });
63+
wrapAsync(() => {
64+
callback(null, ['Data has been', 'processed!']);
65+
});
6266
}
6367

6468
function preprocess(data1, data2, callback) {
65-
console.dir({preprocess:{data1, data2, callback}});
66-
wrapAsync(() => {
67-
callback(null, data1 + ' ' + data2);
68-
});
69+
console.dir({ preprocess: { data1, data2, callback } });
70+
wrapAsync(() => {
71+
callback(null, data1 + ' ' + data2);
72+
});
6973
}

0 commit comments

Comments
 (0)