8000 completed sumAll · cotrones/javascript-exercises@2e85daf · GitHub
[go: up one dir, main page]

Skip to content

Commit 2e85daf

Browse files
committed
completed sumAll
1 parent 6d41ee7 commit 2e85daf

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

sumAll/sumAll.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
1-
const sumAll = function() {
2-
1+
const sumAll = function(x, y) {
2+
let result = 0;
3+
if (!(Number.isInteger(x)) || !(Number.isInteger(y)) || (x < 0) || (y < 0)) {
4+
return 'ERROR';
5+
} else {
6+
if (x > y) {
7+
for (let i = y; i <= x; i++) {
8+
result += i;
9+
}
10+
} else {
11+
for (let i = x; i <= y; i++) {
12+
result += i;
13+
}
14+
}
15+
}
16+
return result;
317
}
418

519
module.exports = sumAll

sumAll/sumAll.spec.js

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

0 commit comments

Comments
 (0)
0