From 0721e9d02263524957e0d06416ff28a118c3ae5b Mon Sep 17 00:00:00 2001 From: LoptrSir <91218015+LoptrSir@users.noreply.github.com> Date: Fri, 11 Mar 2022 09:29:22 -0800 Subject: [PATCH] solution exercise 5 --- 05_sumAll/sumAll.js | 29 +++++++++++++++++++++++++---- 05_sumAll/sumAll.spec.js | 10 +++++----- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/05_sumAll/sumAll.js b/05_sumAll/sumAll.js index 00880c7..643ee33 100644 --- a/05_sumAll/sumAll.js +++ b/05_sumAll/sumAll.js @@ -1,6 +1,27 @@ -const sumAll = function() { - -}; - +const sumAll = function(num1, num2) { + let total = 0; + let a = []; + let b = []; + if (num1 < num2) { + a = num1; + b = num2; +}else { + a = num2; + b = num1; + } + if (a <0 || typeof a == 'string' || typeof b == 'string' || typeof a == 'object' || typeof b == 'object'){ + console.log('ERROR'); + return 'ERROR' + + } + for (i = a; i <= b; i++){ + total += i; + + } + // console.log (a) + console.log(total) + return total + }; + sumAll(5, 7) // Do not edit below this line module.exports = sumAll; diff --git a/05_sumAll/sumAll.spec.js b/05_sumAll/sumAll.spec.js index 1a9fb7c..a171e5f 100644 --- a/05_sumAll/sumAll.spec.js +++ b/05_sumAll/sumAll.spec.js @@ -4,19 +4,19 @@ describe('sumAll', () => { test('sums numbers within the range', () => { expect(sumAll(1, 4)).toEqual(10); }); - test.skip('works with large numbers', () => { + test('works with large numbers', () => { 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); }); - test.skip('returns ERROR with negative numbers', () => { + test('returns ERROR with negative numbers', () => { expect(sumAll(-10, 4)).toEqual('ERROR'); }); - test.skip('returns ERROR with non-number parameters', () => { + test('returns ERROR with non-number parameters', () => { expect(sumAll(10, "90")).toEqual('ERROR'); }); - test.skip('returns ERROR with non-number parameters', () => { + test('returns ERROR with non-number parameters', () => { expect(sumAll(10, [90, 1])).toEqual('ERROR'); }); });