DEV Community

Naveen Dinushka
Naveen Dinushka

Posted on

1 1

Using recursion to count from startNum to endNum (freecodecamp notes)

In this exercise we are asked to write a function which should return an array of integers which begins with a number represented by the startNum parameter and ends with a number represented by the endNum parameter.

So deriving from the previous example of countup , here is how this would work


function rangeOfNumbers(startNum, endNum) {

  if(startNum>endNum){
    return[]
  }
  const rangeArray=rangeOfNumbers(startNum,(endNum-1))
  rangeArray.push(endNum)

  return rangeArray;
};
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

AWS GenAI LIVE!

GenAI LIVE! is a dynamic live-streamed show exploring how AWS and our partners are helping organizations unlock real value with generative AI.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️