Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f7748d4

Browse filesBrowse files
committed
Apply code style
1 parent 286f257 commit f7748d4
Copy full SHA for f7748d4

File tree

Expand file treeCollapse file tree

5 files changed

+72
-68
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+72
-68
lines changed

‎JavaScript/1-imperative.js

Copy file name to clipboardExpand all lines: JavaScript/1-imperative.js
+15-15Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,21 @@ let state = STATE_INIT;
1313
for await (const chunk of process.stdin) {
1414
console.log({ chunk });
1515
switch (state) {
16-
case STATE_INIT:
17-
console.log('initialization');
18-
state = STATE_WORK;
19-
break;
20-
case STATE_WORK:
21-
console.log('working');
22-
state = STATE_FIN;
23-
break;
24-
case STATE_FIN:
25-
console.log('finalization');
26-
state = STATE_EXIT;
27-
break;
28-
case STATE_EXIT:
29-
console.log('exit');
30-
process.exit(0);
16+
case STATE_INIT:
17+
console.log('initialization');
18+
state = STATE_WORK;
19+
break;
20+
case STATE_WORK:
21+
console.log('working');
22+
state = STATE_FIN;
23+
break;
24+
case STATE_FIN:
25+
console.log('finalization');
26+
state = STATE_EXIT;
27+
break;
28+
case STATE_EXIT:
29+
console.log('exit');
30+
process.exit(0);
3131
}
3232
}
3333
})();

‎JavaScript/2-events.js

Copy file name to clipboardExpand all lines: JavaScript/2-events.js
+17-15Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,27 @@ const STATE_EXIT = 3;
99

1010
let state = STATE_INIT;
1111

12-
process.on('SIGINT', () => state = STATE_FIN);
12+
process.on('SIGINT', () => {
13+
state = STATE_FIN;
14+
});
1315

1416
const timer = setInterval(step, TIME_STEP);
1517

1618
function step() {
1719
switch (state) {
18-
case STATE_INIT:
19-
console.log('initialization');
20-
state = STATE_WORK;
21-
break;
22-
case STATE_WORK:
23-
process.stdout.write('.');
24-
break;
25-
case STATE_FIN:
26-
console.log('\nfinalization');
27-
state = STATE_EXIT;
28-
break;
29-
case STATE_EXIT:
30-
console.log('exit');
31-
clearInterval(timer);
20+
case STATE_INIT:
21+
console.log('initialization');
22+
state = STATE_WORK;
23+
break;
24+
case STATE_WORK:
25+
process.stdout.write('.');
26+
break;
27+
case STATE_FIN:
28+
console.log('\nfinalization');
29+
state = STATE_EXIT;
30+
break;
31+
case STATE_EXIT:
32+
console.log('exit');
33+
clearInterval(timer);
3234
}
3335
}

‎JavaScript/3-class.js

Copy file name to clipboardExpand all lines: JavaScript/3-class.js
+14-14Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@ class StateMachine {
77
this.state = StateMachine.STATE.INIT;
88
this.timer = setInterval(() => {
99
switch (this.state) {
10-
case StateMachine.STATE.INIT:
11-
console.log('initialization');
12-
this.state = StateMachine.STATE.WORK;
13-
break;
14-
case StateMachine.STATE.WORK:
15-
process.stdout.write('.');
16-
break;
17-
case StateMachine.STATE.FIN:
18-
console.log('\nfinalization');
19-
this.state = StateMachine.STATE.EXIT;
20-
break;
21-
case StateMachine.STATE.EXIT:
22-
console.log('exit');
23-
clearInterval(this.timer);
10+
case StateMachine.STATE.INIT:
11+
console.log('initialization');
12+
this.state = StateMachine.STATE.WORK;
13+
break;
14+
case StateMachine.STATE.WORK:
15+
process.stdout.write('.');
16+
break;
17+
case StateMachine.STATE.FIN:
18+
console.log('\nfinalization');
19+
this.state = StateMachine.STATE.EXIT;
20+
break;
21+
case StateMachine.STATE.EXIT:
22+
console.log('exit');
23+
clearInterval(this.timer);
2424
}
2525
}, TIME_STEP);
2626
}

‎JavaScript/4-parser.js

Copy file name to clipboardExpand all lines: JavaScript/4-parser.js
+23-23Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,31 @@ class ArrayLiteralParser {
99

1010
feed(char) {
1111
switch (this.state) {
12-
case 'end':
13-
throw new Error(`Unexpected character after array end: ${char}`);
14-
case 'start':
15-
if (char !== '[') {
16-
throw new Error(`Unexpected character before array: ${char}`);
17-
}
18-
this.array = [];
19-
this.state = 'value';
20-
break;
21-
case 'value':
22-
if (char === ',' || char === ']') {
23-
const { value } = this;
24-
this.value = '';
25-
const item = parseFloat(value);
26-
if (Number.isNaN(item)) {
27-
throw new Error(`Can not parse value: ${value}`);
12+
case 'end':
13+
throw new Error(`Unexpected character after array end: ${char}`);
14+
case 'start':
15+
if (char !== '[') {
16+
throw new Error(`Unexpected character before array: ${char}`);
2817
}
29-
this.array.push(item);
30-
if (char === ']') this.state = 'end';
18+
this.array = [];
19+
this.state = 'value';
3120
break;
32-
}
33-
if (!(' .-0123456789').includes(char)) {
34-
throw new Error(`Unexpected character in value: ${char}`);
35-
}
36-
this.value += char;
21+
case 'value':
22+
if (char === ',' || char === ']') {
23+
const { value } = this;
24+
this.value = '';
25+
const item = parseFloat(value);
26+
if (Number.isNaN(item)) {
27+
throw new Error(`Can not parse value: ${value}`);
28+
}
29+
this.array.push(item);
30+
if (char === ']') this.state = 'end';
31+
break;
32+
}
33+
if (!' .-0123456789'.includes(char)) {
34+
throw new Error(`Unexpected character in value: ${char}`);
35+
}
36+
this.value += char;
3737
}
3838
}
3939

‎JavaScript/5-declarative.js

Copy file name to clipboardExpand all lines: JavaScript/5-declarative.js
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ const parser = new ArrayLiteralParser({
3636
'': 'Unexpected character before array',
3737
},
3838
value: {
39-
' .-0123456789': (target, char) => target.value += char,
39+
' .-0123456789': (target, char) => {
40+
target.value += char;
41+
},
4042
',]': (target, char) => {
4143
const value = parseFloat(target.value);
4244
target.result.push(value);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.