Code Lab

Filter a range

EasyFunctions3 min

Write a function filterRange(numbers, a, b) that returns a new array of the numbers from numbers that are at least a and at most b.

Keep the order of the numbers. Do not change the input array.

Examples

filterRange([5, 3, 8, 1], 1, 4)

Returns [ 3, 1 ]

filterRange([1, 2, 3, 4, 5], 2, 4)

Returns [ 2, 3, 4 ]

The bounds `a` and `b` are included.

Source

Loading the editor...
  1. InputfilterRange([ 5, 3, 8, 1 ], 1, 4)
    Expected[ 3, 1 ]
  2. InputfilterRange([ 1, 2, 3, 4, 5 ], 2, 4)
    Expected[ 2, 3, 4 ]
  3. InputfilterRange([ 10, 20 ], 1, 5)
    Expected[]
  4. Returns a new array and keeps the input

Hidden tests run on Submit.