DEV Community

Bukunmi Odugbesan
Bukunmi Odugbesan

Posted on

Coding Challenge Practice - Question 35

The task is to implement a range function.

The boilerplate code

function range(from, to) {
  // your code here
}
Enter fullscreen mode Exit fullscreen mode

Create an empty array to push the results into

const result = []
Enter fullscreen mode Exit fullscreen mode

Use a for loop that starts at "from" and continues till it reaches "to"

for (let i = from; i <= to; i++) {
 result.push(i)
}
Enter fullscreen mode Exit fullscreen mode

The result array is returned. The final code is:

function range(from, to) {
  // your code here
  const result = [];
  for(let i = from; i <= to; i++) {
    result.push(i)
  }
  return result;
}

Enter fullscreen mode Exit fullscreen mode

That's all folks!

Top comments (0)