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?
This commit is contained in:
Dovid Majowka 2020-07-01 01:32:03 +03:00 committed by GitHub
parent 3b51e5dbef
commit a6f97f27a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 0 deletions

View File

@ -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;