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:
parent
3b51e5dbef
commit
a6f97f27a4
|
@ -13,4 +13,22 @@ const sumAll = function(min, max) {
|
||||||
return sum;
|
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;
|
module.exports = sumAll;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue