Problem 6

Integer Range Recursion Challenge

Given two integers x and y, return an array of all integers between them, excluding both endpoints. The range should work in both ascending and descending order.

Function Signature

range(x, y)

Parameters

  • x — an integer representing the start of the range (excluded from result).
  • y — an integer representing the end of the range (excluded from result).

Output

Return an array of integers between x and y, not including x or y. If x is greater than y, return the integers in descending order.

Constraints

  • The function must use recursion.
  • The function should accept exactly two arguments.
  • Both positive and negative integers are valid inputs.

Examples

range(2, 9)    → [3, 4, 5, 6, 7, 8]
range(7, 2)    → [6, 5, 4, 3]
range(3, -3)   → [2, 1, 0, -1, -2]
range(-9, -4)  → [-8, -7, -6, -5]
range(5, 5)    → []
range(2, 3)    → []

Edge Cases

  • If x and y are equal, return an empty array.
  • If x and y are consecutive integers, return an empty array.