Skip to content

Commit 416ea37

Browse files
committed
Code style
1 parent 66aed17 commit 416ea37

File tree

7 files changed

+36
-29
lines changed

7 files changed

+36
-29
lines changed

JavaScript/1-context.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
function hash() {
4-
let data = {};
4+
const data = {};
55
let counter = 0;
66
return function(key, value) {
77
data[key] = value;
@@ -11,8 +11,8 @@ function hash() {
1111
};
1212
}
1313

14-
let h1 = hash();
14+
const h1 = hash();
1515
h1('name', 'Marcus');
1616
h1('city', 'Roma');
17-
let obj1 = h1('born', 121);
17+
const obj1 = h1('born', 121);
1818
console.dir({ obj1 });

JavaScript/2-chain.js

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

33
function hash() {
4-
let data = {};
4+
const data = {};
55
Object.defineProperty(data, 'add', {
66
enumerable: false,
7-
value: function(key, value) {
7+
value(key, value) {
88
data[key] = value;
99
return data;
1010
}
@@ -14,7 +14,7 @@ function hash() {
1414

1515
console.dir(
1616
hash()
17-
.add('name', 'Marcus')
18-
.add('city', 'Roma')
19-
.add('born', 121)
17+
.add('name', 'Marcus')
18+
.add('city', 'Roma')
19+
.add('born', 121)
2020
);

JavaScript/3-closure.js

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

33
function add(x) {
44
return function(y) {
5-
let z = x + y;
5+
const z = x + y;
66
console.log(x + '+' + y + '=' + z);
77
return z;
88
};

JavaScript/4-closure-recursive.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22

33
function add(x) {
44
return function(y) {
5-
let z = x + y;
5+
const z = x + y;
66
console.log(x + '+' + y + '=' + z);
77
return add(z);
88
};
99
}
1010

11-
let a1 = add(5);
12-
let a2 = a1(2);
13-
let a3 = a2(3);
14-
let a4 = a1(1);
15-
let a5 = a2(10);
11+
const a1 = add(5);
12+
const a2 = a1(2);
13+
const a3 = a2(3);
14+
const a4 = a1(1);
15+
const a5 = a2(10);
1616

1717
console.log('--------');
1818

JavaScript/5-logger.js

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

33
function logger(level) {
4-
let color = logger.colors[level] || logger.colors.info;
4+
const color = logger.colors[level] || logger.colors.info;
55
return function(s) {
6-
let date = new Date().toISOString();
6+
const date = new Date().toISOString();
77
console.log(color + date + '\t' + s);
88
};
99
}
@@ -14,9 +14,9 @@ logger.colors = {
1414
info: '\x1b[1;37m'
1515
};
1616

17-
let warning = logger('warning');
18-
let error = logger('error');
19-
let debug = logger('debug');
17+
const warning = logger('warning');
18+
const error = logger('error');
19+
const debug = logger('debug');
2020

2121
warning('Hello');
2222
error('World');

JavaScript/6-functor.js

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

33
function add(x) {
4-
let f = function(y) {
5-
let z = x + y;
4+
const f = function(y) {
5+
const z = x + y;
66
console.log(x + '+' + y + '=' + z);
77
return add(z);
88
};
@@ -12,11 +12,9 @@ function add(x) {
1212
return f;
1313
}
1414

15-
let a1 = add(5);
16-
let a2 = a1(2);
17-
let a3 = a2(3);
18-
let a4 = a1(1);
19-
let a5 = a2(10);
15+
const a1 = add(5);
16+
const a2 = a1(2);
17+
const a3 = a2(3);
18+
const a4 = a1(1);
19+
const a5 = a2(10);
2020
a5.map(console.log);
21-
22-
add(2)(7)(1).map(console.log);

JavaScript/7-functor-min.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use strict';
2+
3+
function add(x) {
4+
const f = y => add(x + y);
5+
f.map = fn => fn(x);
6+
return f;
7+
}
8+
9+
add(2)(7)(1).map(console.log);

0 commit comments

Comments
 (0)