sumAll done
This commit is contained in:
		
							parent
							
								
									e8cdd37d95
								
							
						
					
					
						commit
						2249b5523c
					
				|  | @ -1,5 +1,29 @@ | |||
| const sumAll = function() { | ||||
| const sumAll = function(...args) { | ||||
| 
 | ||||
|     let totalOfNumbers = 0; | ||||
|     let firstNumber = args[0]; | ||||
|     let lastNumber = args[args.length - 1]; | ||||
|     /* If either is not a number, return ERROR */ | ||||
|     if (typeof firstNumber != "number" || typeof lastNumber != "number") { | ||||
|         return 'ERROR'; | ||||
|     } | ||||
|     /* If first number is greater, switch numbers */ | ||||
|     if (firstNumber > lastNumber) { | ||||
|         let tempNumber = firstNumber; | ||||
|         firstNumber = lastNumber; | ||||
|         lastNumber = tempNumber; | ||||
|     } | ||||
| 
 | ||||
|     /*If either number is negative, return 'ERROR' */ | ||||
|     if (firstNumber < 0 || lastNumber < 0) { | ||||
|         return 'ERROR'; | ||||
|     } | ||||
| 
 | ||||
|     for (let i = firstNumber; i <= lastNumber; i++) { | ||||
|         totalOfNumbers += i; | ||||
|     } | ||||
|     return totalOfNumbers; | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| module.exports = sumAll | ||||
| module.exports = sumAll | ||||
|  | @ -1,22 +1,22 @@ | |||
| const sumAll = require('./sumAll') | ||||
| 
 | ||||
| describe('sumAll', function() { | ||||
|   it('sums numbers within the range', function() { | ||||
|     expect(sumAll(1, 4)).toEqual(10); | ||||
|   }); | ||||
|   xit('works with large numbers', function() { | ||||
|     expect(sumAll(1, 4000)).toEqual(8002000); | ||||
|   }); | ||||
|   xit('works with larger number first', function() { | ||||
|     expect(sumAll(123, 1)).toEqual(7626); | ||||
|   }); | ||||
|   xit('returns ERROR with negative numbers', function() { | ||||
|     expect(sumAll(-10, 4)).toEqual('ERROR'); | ||||
|   }); | ||||
|   xit('returns ERROR with non-number parameters', function() { | ||||
|     expect(sumAll(10, "90")).toEqual('ERROR'); | ||||
|   }); | ||||
|   xit('returns ERROR with non-number parameters', function() { | ||||
|     expect(sumAll(10, [90, 1])).toEqual('ERROR'); | ||||
|   }); | ||||
| }); | ||||
|     it('sums numbers within the range', function() { | ||||
|         expect(sumAll(1, 4)).toEqual(10); | ||||
|     }); | ||||
|     it('works with large numbers', function() { | ||||
|         expect(sumAll(1, 4000)).toEqual(8002000); | ||||
|     }); | ||||
|     it('works with larger number first', function() { | ||||
|         expect(sumAll(123, 1)).toEqual(7626); | ||||
|     }); | ||||
|     it('returns ERROR with negative numbers', function() { | ||||
|         expect(sumAll(-10, 4)).toEqual('ERROR'); | ||||
|     }); | ||||
|     it('returns ERROR with non-number parameters', function() { | ||||
|         expect(sumAll(10, "90")).toEqual('ERROR'); | ||||
|     }); | ||||
|     it('returns ERROR with non-number parameters', function() { | ||||
|         expect(sumAll(10, [90, 1])).toEqual('ERROR'); | ||||
|     }); | ||||
| }); | ||||
		Loading…
	
		Reference in New Issue