From a6f97f27a477ff3dae34bcbf5fd33feef4e860cb Mon Sep 17 00:00:00 2001 From: Dovid Majowka <36450233+DoviMaj@users.noreply.github.com> Date: Wed, 1 Jul 2020 01:32:03 +0300 Subject: [PATCH] can include option using reduce method since its a more advanced method its helpful to show how it would be done with it. what do you think? --- sumAll/sumAll.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/sumAll/sumAll.js b/sumAll/sumAll.js index 1429afa..11d224c 100644 --- a/sumAll/sumAll.js +++ b/sumAll/sumAll.js @@ -13,4 +13,22 @@ const sumAll = function(min, max) { return sum; }; +// A more advanced way using reduce method + +// const sumAll = function(min, max) { +// if(min < 0 || max < 0 || typeof min !== 'number'|| typeof max !== 'number' ) return 'ERROR'; +// if(min > max){ +// const temp = min; +// min = max; +// max = temp; +// } +// const arr = []; +// for(i= min; i <= max; i++){ +// arr.push(i); +// } +// return arr.reduce((a, b) => a + b); +// } + + module.exports = sumAll; +