Skip to content

Instantly share code, notes, and snippets.

@IsraaMoqbel
Created July 26, 2022 22:27
Show Gist options
  • Select an option

  • Save IsraaMoqbel/fcc9503f3415743f3dfda2e068b68d1d to your computer and use it in GitHub Desktop.

Select an option

Save IsraaMoqbel/fcc9503f3415743f3dfda2e068b68d1d to your computer and use it in GitHub Desktop.
Get integers between x & y using recursion.
/*
Write a JavaScript program to get the integers in range (x, y).
Example : range(2, 9)
Expected Output : [3, 4, 5, 6, 7, 8]
*/
function getBetween(x, y) {
if (x == y) {
return [x]
} else {
const numbers = getBetween(x, y - 1)
numbers.push(y)
return numbers
}
}
console.log(getBetween(3, 7)) // [ 3, 4, 5, 6, 7 ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment