We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a03a1c4 commit 43b2582Copy full SHA for 43b2582
chapter_01-the_basics_of_unit_testing/SimpleParser/simpleParser.js
@@ -0,0 +1,26 @@
1
+const InvalidOperationError = require('./InvalidOperationError');
2
+
3
+function simpleParser() {
4
+ /**
5
+ * @param {string} numbers
6
+ * @return {number}
7
+ */
8
+ function parseAndSum(numbers) {
9
+ if (numbers.length === 0) {
10
+ return 0;
11
+ }
12
+ if (!numbers.includes(',')) {
13
+ return Number(numbers);
14
+ } else {
15
+ throw new InvalidOperationError(
16
+ 'I can only handle 0 or 1 numbers for now!'
17
+ );
18
19
20
21
+ return {
22
+ parseAndSum,
23
+ };
24
+}
25
26
+module.exports = simpleParser;
0 commit comments