Use Recursion to Return a Range Array

using recursion to return a range array between the two numbers added


* {
  box-sizing: border-box;
  transition: all 0.2s;
  scroll-behavior: smooth;


function run_function() {
  var my_result = "A Result";
  return my_result;

function rangeOfNumbers(startNum, endNum) {
  if (startNum === endNum) {
    return [startNum];
  } else {
    const endNumMinus = endNum - 1;
    const startNumMinus = startNum - 1;
    const countArray = rangeOfNumbers(startNum, endNumMinus);
    return countArray;
console.log(rangeOfNumbers(4, 6));

// this is a common function just to write the content into the result div
function write_result(result) {
  var result_html = document.getElementById("result");
  result_html.innerHTML = result;


<div id='result' class='mb-3 alert alert-primary'>..</div>
<button onclick='run_function();' class='btn btn-primary mb-1'>Run Function</button>

Working Result


External Link for Use Recursion to Return a Range Array

Other Items in javascript
Page Views

This page has been viewed 378 times.

Search Code
Search Code by entering your search text above.

This is my test area for webdev. I keep a collection of code snippits here, mostly for my reference. Also if i find a good site, i usually add it here.


Random Quote
For a long time it had seemed to me that life was about to begin - real life. But there was always some obstacle in the way, something to be gotten through first, some unfinished business, time still to be served, or a debt to be paid. Then life would begin. At last it dawned on me that these obstacles were my life.
Alfred D. Souza