Skip to content

Commit 095e5f4

Browse files
committed
Improve examples
1 parent de9a690 commit 095e5f4

6 files changed

Lines changed: 13 additions & 19 deletions

File tree

JavaScript/1-callback.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,4 @@ const add = (a, b) => a + b;
44
const sum = (a, b, callback) => callback(a + b);
55

66
console.log('Use add: ' + add(5, 2));
7-
8-
sum(5, 2, (result) => {
9-
console.log('Use sum: ' + result);
10-
});
7+
sum(5, 2, console.log.bind(null, 'Use sum:'));

JavaScript/5-timer-curry.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const fn = () => {
1414
const setTimeoutCallbackLast = (timeout, fn) => setTimeout(fn, timeout);
1515

1616
const timer = curry(setTimeoutCallbackLast);
17-
timer(5000)(fn);
17+
timer(2000)(fn);
1818

19-
const timer5s = timer(5000);
19+
const timer5s = timer(2000);
2020
timer5s(fn);

JavaScript/7-listener-timer.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@ const iterate = (array, listener) => {
55
setInterval(() => {
66
listener(array[counter++]);
77
if (counter >= array.length) counter = 0;
8-
}, 5000);
8+
}, 1000);
99
};
1010

1111
const cities = ['Kiev', 'London', 'Beijing'];
1212

13-
const fn = (city) => {
14-
console.log('Next city: ' + city);
15-
};
13+
const fn = city => console.log('Next city: ' + city);
1614

1715
iterate(cities, fn);

JavaScript/8-event.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
'use strict';
22

3-
const adder = (value) => {
4-
const add = (a) => {
5-
value += a;
3+
const adder = (initial) => {
4+
let value = initial;
5+
const add = (delta) => {
6+
value += delta;
67
if (value >= add.maxValue) add.maxEvent(value);
78
return add;
89
};
@@ -20,7 +21,7 @@ const maxReached = (value) => {
2021
console.log('max value reached, value: ' + value);
2122
};
2223

23-
const a1 = adder(10).max(100, maxReached)(-5);
24+
const a1 = adder(10).max(100, maxReached)(-12);
2425

2526
a1(25);
2627
a1(50);

JavaScript/a-deferred.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@ const conferences = getConferences();
1717

1818
console.log(conferences);
1919

20-
conferences.data(5);
21-
22-
/*conferences.data((list) => {
20+
conferences.data((list) => {
2321
console.log(list);
24-
});*/
22+
});
2523

2624
console.log('end');

JavaScript/b-errors.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const adder = (value) => {
2727
const maxReached = (err, value) => {
2828
if (err) {
2929
console.log('value: ' + value);
30-
throw err;
30+
//throw err;
3131
}
3232
};
3333

0 commit comments

Comments
 (0)