Passes test 4 from exercise 05

This commit is contained in:
NetMan 2024-01-05 21:46:07 +01:00
parent 56cdd5935c
commit 77972b4282
2 changed files with 4 additions and 1 deletions

View File

@ -1,4 +1,7 @@
const sumAll = function(a, b) { const sumAll = function(a, b) {
if (a < 0 || b < 0) {
return "ERROR";
}
let c, sum = 0; let c, sum = 0;
for ((a > b) ? (i = b, c = a) for ((a > b) ? (i = b, c = a)
: (i = a, c = b); i <= c; i++) { : (i = a, c = b); i <= c; i++) {

View File

@ -10,7 +10,7 @@ describe('sumAll', () => {
test('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('returns ERROR with negative numbers', () => {
expect(sumAll(-10, 4)).toEqual('ERROR'); expect(sumAll(-10, 4)).toEqual('ERROR');
}); });
test.skip('returns ERROR with non-number parameters', () => { test.skip('returns ERROR with non-number parameters', () => {