Array.filter I - numbers
Easy
13
60.0% Acceptance
Implement a function called getLessThanFive(numbers)
that takes an array of numbers as input and returns a new array containing only the elements that are strictly less than 5.
Instructions
- If no elements in the input array are less than 5, return an empty array.
Example test cases
const numbers = [2, 6, 3, 7, 1, 9, 4]; const lessThanFive = getLessThanFive(numbers); console.log(lessThanFive); // Output: [2, 3, 1, 4]
Hints
- You can create a new array, loop over the input array
numbers
and conditionally push the element to the new array. - You can use the built-in method
.filter()
method. - On each iteration of the loop, check if the current number is less than 5.