8000 Add Solution to Exercise 05 · TezzGit/javascript-exercises@723faa7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 723faa7

Browse files
committed
Add Solution to Exercise 05
1 parent 849c786 commit 723faa7

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

05_sumAll/sumAll.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
1-
const sumAll = function() {
1+
const sumAll = function (num1, num2) {
2+
if (!Number.isInteger(num1) || !Number.isInteger(num2)) {
3+
return 'ERROR'
4+
}
5+
else if (num1 < 0 || num2 < 0) {
6+
return 'ERROR'
7+
}
28

9+
let largestNumber = num1 > num2 ? num1 : num2
10+
let smallestNumber = num1 < num2 ? num1 : num2
11+
let answer = 0;
12+
while (smallestNumber <= largestNumber) {
13+
answer += smallestNumber
14+
smallestNumber++
15+
}
16+
return answer
317
};
418

519
// Do not edit below this line

05_sumAll/sumAll.spec.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ describe('sumAll', () => {
44
test('sums numbers within the range', () => {
55
expect(sumAll(1, 4)).toEqual(10);
66
});
7-
test.skip('works with large numbers', () => {
7+
test('works with large numbers', () => {
88
expect(sumAll(1, 4000)).toEqual(8002000);
99
});
10-
test.skip('works with larger number first', () => {
10+
test('works with larger number first', () => {
1111
expect(sumAll(123, 1)).toEqual(7626);
1212
});
13-
test.skip('returns ERROR with negative numbers', () => {
13+
test('returns ERROR with negative numbers', () => {
1414
expect(sumAll(-10, 4)).toEqual('ERROR');
1515
});
16-
test.skip('returns ERROR with non-number parameters', () => {
16+
test('returns ERROR with non-number parameters', () => {
1717
expect(sumAll(10, "90")).toEqual('ERROR');
1818
});
19-
test.skip('returns ERROR with non-number parameters', () => {
19+
test('returns ERROR with non-number parameters', () => {
2020
expect(sumAll(10, [90, 1])).toEqual('ERROR');
2121
});
2222
});

0 commit comments

Comments
 (0)
0