From 56cdd5935c1f45c82202d1e1810a2f1066c11ff9 Mon Sep 17 00:00:00 2001 From: NetMan <13informatyka14@gmail.com> Date: Fri, 5 Jan 2024 21:43:56 +0100 Subject: [PATCH] Passes test 3 from exercise 05 --- 05_sumAll/sumAll.js | 5 +++-- 05_sumAll/sumAll.spec.js | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/05_sumAll/sumAll.js b/05_sumAll/sumAll.js index e733b01..16f3de7 100644 --- a/05_sumAll/sumAll.js +++ b/05_sumAll/sumAll.js @@ -1,6 +1,7 @@ const sumAll = function(a, b) { - let sum = 0; - for (let i = a; i <= b; i++) { + let c, sum = 0; + for ((a > b) ? (i = b, c = a) + : (i = a, c = b); i <= c; i++) { sum += i; } return sum; diff --git a/05_sumAll/sumAll.spec.js b/05_sumAll/sumAll.spec.js index e2f1c95..6c53087 100644 --- a/05_sumAll/sumAll.spec.js +++ b/05_sumAll/sumAll.spec.js @@ -7,7 +7,7 @@ describe('sumAll', () => { 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', () => {