Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 90e1f85

Browse files
committedFeb 15, 2022
Update code style
1 parent 2023c35 commit 90e1f85

File tree

7 files changed

+23
-15
lines changed

7 files changed

+23
-15
lines changed
 

‎JavaScript/1-identifiers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Arguments instead of mutable variables assignment
44

55
const { PI, sqrt } = Math;
6-
const square = x => x * x;
6+
const square = (x) => x * x;
77

88
// Imperative
99

‎JavaScript/2-condition.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const person = {
2424
// Functional
2525

2626
{
27-
const era = year => (year < 0 ? 'BC' : 'AD');
27+
const era = (year) => (year < 0 ? 'BC' : 'AD');
2828
const { name, born } = person;
2929
const output = `${name} was born in ${born} ${era(born)}`;
3030
console.dir(output);

‎JavaScript/3-iteration.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const loop = (min, max, fn) => {
1818
for (let i = min; i < max; i++) fn(i);
1919
};
2020

21-
loop(0, numbers.length, i => {
21+
loop(0, numbers.length, (i) => {
2222
const n = numbers[i];
2323
console.log(`Item ${i} is ${n}`);
2424
});

‎JavaScript/4-arguments.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ const max = (a, b) => {
88
if (a > b) return a;
99
else return b;
1010
};
11+
1112
console.log(max(3, 5));
1213

1314
// Functional
1415

15-
const maxc = a => b => (a > b ? a : b);
16+
const maxc = (a) => (b) => (a > b ? a : b);
1617
console.log(maxc(3)(5));

‎JavaScript/5-instance.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@
77
const marcus1 = {
88
name: 'Marcus Aurelius',
99
born: 121,
10+
1011
upperName() {
1112
this.name = this.name.toUpperCase();
1213
},
14+
1315
get era() {
1416
return this.born < 0 ? 'BC' : 'AD';
1517
},
18+
1619
toString() {
1720
return `${this.name} was born in ${this.born} ${this.era}`;
1821
},
@@ -29,7 +32,7 @@ console.log('Fields:', keys.join(', '));
2932

3033
// Functional
3134

32-
const era = year => (year < 0 ? 'BC' : 'AD');
35+
const era = (year) => (year < 0 ? 'BC' : 'AD');
3336
const person = (name, born) => () => `${name} was born in ${born} ${era(born)}`;
3437

3538
const marcus2 = person('Marcus Aurelius', 121, 'Roma');

‎JavaScript/6-mapping.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const marcus3 = {
3434

3535
const marcus4 = omap(marcus3, (key, val) => [
3636
key.toLowerCase().replace('name', ''),
37-
val.toUpperCase()
37+
val.toUpperCase(),
3838
]);
3939

4040
console.log(marcus4);

‎JavaScript/7-chaining.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ class Adder {
66
constructor(initial) {
77
this.value = initial;
88
}
9-
add(value) {
10-
this.value += value;
9+
10+
add(x) {
11+
this.value += x;
1112
return this;
1213
}
14+
1315
valueOf() {
1416
return this.value;
1517
}
@@ -20,10 +22,12 @@ console.log('Sum:', +sum1);
2022

2123
// Functional
2224

23-
const adder = initial => Object.assign(
24-
value => adder(initial + value),
25-
{ valueOf: () => initial,
26-
map: log => log(initial) }
25+
const adder = (initial) => Object.assign(
26+
(value) => adder(initial + value),
27+
{
28+
valueOf: () => initial,
29+
map: (log) => log(initial),
30+
}
2731
);
2832

2933
const sum2 = adder(1)(9)(1)(7);
@@ -32,9 +36,9 @@ sum2.map(console.log);
3236

3337
// Functional methods
3438

35-
const add = initial => ({
36-
add: value => add(initial + value),
37-
valueOf: () => initial
39+
const add = (initial) => ({
40+
add: (value) => add(initial + value),
41+
valueOf: () => initial,
3842
});
3943

4044
const sum3 = add(1).add(9).add(1).add(7);

0 commit comments

Comments
 (0)
Please sign in to comment.