Added Comments to 05_sumAll solution
This commit is contained in:
parent
43a8b165b4
commit
a2ca64e0b6
|
@ -1,5 +1,5 @@
|
||||||
const helloWorld = function() {
|
const helloWorld = function() {
|
||||||
return ''
|
return ''
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = helloWorld;
|
module.exports = helloWorld;
|
||||||
|
|
|
@ -1,6 +1,13 @@
|
||||||
const sumAll = function (min, max) {
|
const sumAll = function (min, max) {
|
||||||
|
// The Line of code below returns "ERROR" which is a string if min and max aren't numbers
|
||||||
if (!Number.isInteger(min) || !Number.isInteger(max)) return "ERROR";
|
if (!Number.isInteger(min) || !Number.isInteger(max)) return "ERROR";
|
||||||
|
// This line of code also returns "ERROR" is min and max are less than 0
|
||||||
if (min < 0 || max < 0) return "ERROR";
|
if (min < 0 || max < 0) return "ERROR";
|
||||||
|
/*
|
||||||
|
The block of code below checks if min is greater than max
|
||||||
|
And if that is true, a new variable called 'temp' is created
|
||||||
|
The value of 'temp' will be equal to min and max will be equal to temp
|
||||||
|
*/
|
||||||
if (min > max) {
|
if (min > max) {
|
||||||
const temp = min;
|
const temp = min;
|
||||||
min = max;
|
min = max;
|
||||||
|
@ -12,6 +19,10 @@ const sumAll = function (min, max) {
|
||||||
// if (min > max) [min, max] = [max, min];
|
// if (min > max) [min, max] = [max, min];
|
||||||
|
|
||||||
let sum = 0;
|
let sum = 0;
|
||||||
|
/* We're running a for loop below which
|
||||||
|
Initializes the value of i to be that of min and we're checking if i is less than or equal to max
|
||||||
|
And if those conditions are true, we'll be adding i to value of sum
|
||||||
|
*/
|
||||||
for (let i = min; i <= max; i++) {
|
for (let i = min; i <= max; i++) {
|
||||||
sum += i;
|
sum += i;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue