Passed returns ERROR with negative numbers

This commit is contained in:
Mohammed Nabeel 2020-07-17 10:55:13 +03:00
parent 607fcec7ca
commit 24cf26a15f
2 changed files with 6 additions and 1 deletions

View File

@ -16,6 +16,11 @@ const sumAll = function(...args) {
lastNumber = tempNumber; lastNumber = tempNumber;
} }
/*If either number is negative, return 'ERROR' */
if (firstNumber < 0 || lastNumber < 0) {
return 'ERROR';
}
for (let i = firstNumber; i <= lastNumber; i++) { for (let i = firstNumber; i <= lastNumber; i++) {
totalOfNumbers += i; totalOfNumbers += i;
} }

View File

@ -10,7 +10,7 @@ describe('sumAll', function() {
it('works with larger number first', function() { it('works with larger number first', function() {
expect(sumAll(123, 1)).toEqual(7626); expect(sumAll(123, 1)).toEqual(7626);
}); });
xit('returns ERROR with negative numbers', function() { it('returns ERROR with negative numbers', function() {
expect(sumAll(-10, 4)).toEqual('ERROR'); expect(sumAll(-10, 4)).toEqual('ERROR');
}); });
xit('returns ERROR with non-number parameters', function() { xit('returns ERROR with non-number parameters', function() {