Passes test 3 from exercise 05
This commit is contained in:
parent
43e2839177
commit
56cdd5935c
|
@ -1,6 +1,7 @@
|
||||||
const sumAll = function(a, b) {
|
const sumAll = function(a, b) {
|
||||||
let sum = 0;
|
let c, sum = 0;
|
||||||
for (let i = a; i <= b; i++) {
|
for ((a > b) ? (i = b, c = a)
|
||||||
|
: (i = a, c = b); i <= c; i++) {
|
||||||
sum += i;
|
sum += i;
|
||||||
}
|
}
|
||||||
return sum;
|
return sum;
|
||||||
|
|
|
@ -7,7 +7,7 @@ describe('sumAll', () => {
|
||||||
test('works with large numbers', () => {
|
test('works with large numbers', () => {
|
||||||
expect(sumAll(1, 4000)).toEqual(8002000);
|
expect(sumAll(1, 4000)).toEqual(8002000);
|
||||||
});
|
});
|
||||||
test.skip('works with larger number first', () => {
|
test('works with larger number first', () => {
|
||||||
expect(sumAll(123, 1)).toEqual(7626);
|
expect(sumAll(123, 1)).toEqual(7626);
|
||||||
});
|
});
|
||||||
test.skip('returns ERROR with negative numbers', () => {
|
test.skip('returns ERROR with negative numbers', () => {
|
||||||
|
|
Loading…
Reference in New Issue