Code Lab

Mode entretien. Minuteur de 3 min, sans indices ni autocomplétion

Filter a range

FacileFunctions3 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.

Exemples

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

Renvoie [ 3, 1 ]

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

Renvoie [ 2, 3, 4 ]

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

Source

Chargement de l'éditeur...
  1. EntréefilterRange([ 5, 3, 8, 1 ], 1, 4)
    Attendu[ 3, 1 ]
  2. EntréefilterRange([ 1, 2, 3, 4, 5 ], 2, 4)
    Attendu[ 2, 3, 4 ]
  3. EntréefilterRange([ 10, 20 ], 1, 5)
    Attendu[]
  4. Returns a new array and keeps the input

Les tests cachés se lancent à la soumission