re: Solving "Sum All Numbers in a Range" / freeCodeCamp Algorithm Challenges VIEW POST


Hi Viren,

Thanks for sharing! Just want to ask why not just add numbers in for loop. Like below

  let sum = 0;
  for (let i = arr[0]; i <= arr[1]; i++) {
    sum+= i
  return sum

Is there any problem with this method? Thanks.


No. There is no problem in your methodology. But I think you assumed that arr[0] <= arr[1] ? Have your read description carefully?

code of conduct - report abuse