0
const sequenceSum = (begin, end) => {
  // BEGIN (write your solution here)
  if (begin === end) {
    return end;
  } else if (begin > end) {
    return NaN;
  }

  return end + sequenceSum(end-1);
  // END
};

export default sequenceSum;

Hello. I don't the understand problem with the above code. I've got the following error:

RangeError: Maximum call stack size exceeded

2
  • 1
    Looks like the recursion never stops. How exactly, i.e. with what arguments, do you call that function? Commented Jul 19, 2017 at 6:29
  • xyproblem.info Commented Jul 19, 2017 at 6:37

1 Answer 1

3

You do not provide second parameter to function call at return end + sequenceSum(end-1) resulting in neither if nor if..else statement being reached, as end is not defined; instead return end + sequenceSum(end-1) is called repeatedly.

Sign up to request clarification or add additional context in comments.

1 Comment

Yea, thank you! return end + sequenceSum(begin, end-1); :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.