Code Lab

Modo entrevista. Cronômetro de 3 min, sem dicas e sem autocompletar

Filter a range

FácilFunctions3 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.

Exemplos

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

Retorna [ 3, 1 ]

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

Retorna [ 2, 3, 4 ]

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

Fonte

Carregando o editor...
  1. EntradafilterRange([ 5, 3, 8, 1 ], 1, 4)
    Esperado[ 3, 1 ]
  2. EntradafilterRange([ 1, 2, 3, 4, 5 ], 2, 4)
    Esperado[ 2, 3, 4 ]
  3. EntradafilterRange([ 10, 20 ], 1, 5)
    Esperado[]
  4. Returns a new array and keeps the input

Os testes ocultos rodam no envio