Explorer
Node.js

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); } ```

Array.filter

Easy
Write a function `getEvens(arr)` that returns only even numbers from the array.
Editor
Loading Editor...
Evaluate code
Output:Click "Run" above to execute and verify your code here.
[2,4,6,8]