File tree Expand file tree Collapse file tree 10 files changed +130
-0
lines changed Expand file tree Collapse file tree 10 files changed +130
-0
lines changed Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ const sum = ( ...args ) => {
4
+ // Use for loop and accumulator variable
5
+ // to calculate sum of all given arguments
6
+ // For example sum(1, 2, 3) should return 6
7
+ } ;
8
+
9
+ module . exports = { sum } ;
Original file line number Diff line number Diff line change
1
+ ({
2
+ name: 'sum',
3
+ length: [70, 130],
4
+ cases: [
5
+ [1, 2, 3, 6],
6
+ [0, 0],
7
+ [0],
8
+ [1, -1, 1, 1],
9
+ [10, -1, -1, -1, 7],
10
+ ],
11
+ test: sum => {
12
+ const src = sum.toString();
13
+ if (!src.includes('for (')) throw new Error('Use for loop');
14
+ if (!src.includes('for (let')) throw new Error('Use let for accumulator');
15
+ if (!src.includes('return')) throw new Error('Use return');
16
+ }
17
+ })
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ const sum = ( ...args ) => {
4
+ // Use for..of loop and accumulator variable
5
+ // to calculate sum of all given arguments
6
+ // For example sum(1, 2, 3) should return 6
7
+ } ;
8
+
9
+ module . exports = { sum } ;
Original file line number Diff line number Diff line change
1
+ ({
2
+ name: 'sum',
3
+ length: [70, 130],
4
+ cases: [
5
+ [1, 2, 3, 6],
6
+ [0, 0],
7
+ [0],
8
+ [1, -1, 1, 1],
9
+ [10, -1, -1, -1, 7],
10
+ ],
11
+ test: sum => {
12
+ const src = sum.toString();
13
+ if (!src.includes('for (')) throw new Error('Use for..of loop');
14
+ if (!src.includes(' of ')) throw new Error('Use for..of in loop');
15
+ if (!src.includes('for (const')) throw new Error('Use const in loop');
16
+ if (!src.includes('let')) throw new Error('Use let to define accumulator');
17
+ if (!src.includes('return')) throw new Error('Use return');
18
+ }
19
+ })
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ const sum = ( ...args ) => {
4
+ // Use while loop and accumulator variable
5
+ // to calculate sum of all given arguments
6
+ // For example sum(1, 2, 3) should return 6
7
+ } ;
8
+
9
+ module . exports = { sum } ;
Original file line number Diff line number Diff line change
1
+ ({
2
+ name: 'sum',
3
+ length: [100, 130],
4
+ cases: [
5
+ [1, 2, 3, 6],
6
+ [0, 0],
7
+ [0],
8
+ [1, -1, 1, 1],
9
+ [10, -1, -1, -1, 7],
10
+ ],
11
+ test: sum => {
12
+ const src = sum.toString();
13
+ if (!src.includes('while (')) throw new Error('Use while loop');
14
+ if (!src.includes('let')) throw new Error('Use let to define accumulator');
15
+ if (!src.includes('return')) throw new Error('Use return');
16
+ }
17
+ })
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ const sum = ( ...args ) => {
4
+ // Use do..while loop and accumulator variable
5
+ // to calculate sum of all given arguments
6
+ // For example sum(1, 2, 3) should return 6
7
+ } ;
8
+
9
+ module . exports = { sum } ;
Original file line number Diff line number Diff line change
1
+ ({
2
+ name: 'sum',
3
+ length: [130, 160],
4
+ cases: [
5
+ [1, 2, 3, 6],
6
+ [0, 0],
7
+ [0],
8
+ [1, -1, 1, 1],
9
+ [10, -1, -1, -1, 7],
10
+ ],
11
+ test: sum => {
12
+ const src = sum.toString();
13
+ if (!src.includes('while (')) throw new Error('Use while loop');
14
+ if (!src.includes('let')) throw new Error('Use let to define accumulator');
15
+ if (!src.includes('return')) throw new Error('Use return');
16
+ }
17
+ })
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ const sum = ( ...args ) => 0 ;
4
+ // Use Array.prototype.reduce method
5
+ // to calculate sum of all given arguments
6
+ // For example sum(1, 2, 3) should return 6
7
+
8
+ module . exports = { sum } ;
Original file line number Diff line number Diff line change
1
+ ({
2
+ name: 'sum',
3
+ length: [40, 60],
4
+ cases: [
5
+ [1, 2, 3, 6],
6
+ [0, 0],
7
+ [0],
8
+ [1, -1, 1, 1],
9
+ [10, -1, -1, -1, 7],
10
+ ],
11
+ test: sum => {
12
+ const src = sum.toString();
13
+ if (!src.includes('.reduce(')) throw new Error('Use reduce method');
14
+ if (src.includes('return')) throw new Error('Do not use return');
15
+ }
16
+ })
You can’t perform that action at this time.
0 commit comments