Created
July 26, 2022 22:27
-
-
Save IsraaMoqbel/fcc9503f3415743f3dfda2e068b68d1d to your computer and use it in GitHub Desktop.
Get integers between x & y using recursion.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| 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