mirror of
https://github.com/10h30/odin-javascript-exercises.git
synced 2026-07-11 18:55:59 +09:00
+2
-17
@@ -1,20 +1,5 @@
|
||||
var sumAll = function(a, b) {
|
||||
if (a > b) {
|
||||
let temp = a
|
||||
a = b
|
||||
b = temp
|
||||
}
|
||||
if (
|
||||
a < 0 || b < 0 ||
|
||||
typeof a != 'number' || typeof b != 'number'
|
||||
) {
|
||||
return 'ERROR'
|
||||
}
|
||||
let sum = 0
|
||||
for(let i = a; i < b + 1; i++) {
|
||||
sum += i
|
||||
}
|
||||
return sum
|
||||
var sumAll = function() {
|
||||
|
||||
}
|
||||
|
||||
module.exports = sumAll
|
||||
|
||||
@@ -4,19 +4,19 @@ describe('sumAll', function() {
|
||||
it('sums numbers within the range', function() {
|
||||
expect(sumAll(1, 4)).toEqual(10);
|
||||
});
|
||||
it('works with large numbers', function() {
|
||||
xit('works with large numbers', function() {
|
||||
expect(sumAll(1, 4000)).toEqual(8002000);
|
||||
});
|
||||
it('works with larger number first', function() {
|
||||
xit('works with larger number first', function() {
|
||||
expect(sumAll(123, 1)).toEqual(7626);
|
||||
});
|
||||
it('returns ERROR with negative numbers', function() {
|
||||
xit('returns ERROR with negative numbers', function() {
|
||||
expect(sumAll(-10, 4)).toEqual('ERROR');
|
||||
});
|
||||
it('returns ERROR with non-number parameters', function() {
|
||||
xit('returns ERROR with non-number parameters', function() {
|
||||
expect(sumAll(10, "90")).toEqual('ERROR');
|
||||
});
|
||||
it('returns ERROR with non-number parameters', function() {
|
||||
xit('returns ERROR with non-number parameters', function() {
|
||||
expect(sumAll(10, [90, 1])).toEqual('ERROR');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user