Design a Sum All Numbers Algorithm - Design a Sum All Numbers Algorithm

Tell us what’s happening:

Why would I use the rest operator when the number of arguments is defined in the problem statement?

Your code so far

function sumAll([n, m]) {
  let sum = 0;
  const start = Math.min(n, m);
  const end = Math.max(n, m);
  for (let addend = start; addend <= end; addend++) {
    sum += addend;
  }
  return sum;
}

console.log(sumAll([1, 4]))

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.1 Safari/605.1.15 Ddg/26.1

Challenge Information:

Design a Sum All Numbers Algorithm - Design a Sum All Numbers Algorithm

Can you describe what you mean?

I don’t think this is mentioned in the instructions?

EDIT: Do you mean why use a list for the argument?

I was just curious, given the placement of the exercise (near the discussion of the rest operator) and several other learner’s whose solutions I looked at on the forum. I wondered if I’m missing something about the power of the rest operator or something like that. Could be I’m just over-thinking it :zany_face:.

if you don’t need it don’t use it. The rest operator is something you need to know about, but you don’t need to always use it, we had put it here because there was a lab that needed it, but maybe it has been moved later

:ok_hand: thanks for replying, always good to know.