Write a function `getEvens(arr)` that returns only even numbers from the array.
Problem Statement
Write a function `getEvens(arr)` that returns only even numbers from the array.
Complexity
Time Complexity: -
Space Complexity: -
Hints
š” Hint 1:
Array.filter() creates a new array with elements that pass a test.
š” Hint 2:
A number is even if n % 2 === 0.
š” Hint 3:
return arr.filter(n => n % 2 === 0);
ā
Solution:
```javascript
function getEvens(arr) {
return arr.filter(n => n % 2 === 0);
}
```