Skip to content

Commit 420e090

Browse files
committed
Refactor: fail fast
1 parent f31f5ab commit 420e090

File tree

4 files changed

+4
-9
lines changed

4 files changed

+4
-9
lines changed

JavaScript/1-sync-try.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
const sum = (a, b) => {
44
if (typeof a === 'number' && typeof b === 'number') {
55
return a + b;
6-
} else {
7-
throw new Error('a and b should be numbers');
86
}
7+
throw new Error('a and b should be numbers');
98
};
109

1110
try {

JavaScript/2-sync-tuple.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
const sum = (a, b) => {
44
if (typeof a === 'number' && typeof b === 'number') {
55
return [null, a + b];
6-
} else {
7-
return [new Error('a and b should be numbers')];
86
}
7+
return [new Error('a and b should be numbers')];
98
};
109

1110
console.log(sum(2, 3));

JavaScript/4-uncaught.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@ process.on('uncaughtException', (err) => {
88
const sum = (a, b) => {
99
if (typeof a === 'number' && typeof b === 'number') {
1010
return a + b;
11-
} else {
12-
throw new Error('a and b should be numbers');
1311
}
12+
throw new Error('a and b should be numbers');
1413
};
1514

1615
console.log(sum(2, 3));
17-
1816
console.log(sum(7, 'A'));

JavaScript/6-async-await.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
const sum = async (a, b) => {
44
if (typeof a === 'number' && typeof b === 'number') {
55
return a + b;
6-
} else {
7-
throw new Error('a and b should be numbers');
86
}
7+
throw new Error('a and b should be numbers');
98
};
109

1110
(async () => {

0 commit comments

Comments
 (0)