Passes test 3 from exercise 05

This commit is contained in:
NetMan 2024-01-05 21:43:56 +01:00
parent 43e2839177
commit 56cdd5935c
2 changed files with 4 additions and 3 deletions

View File

@ -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;

View File

@ -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', () => {