Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Filter Even Numbers

Working With Arrayseasy

Course · Section 11: Working With Arrays · Lecture 156: Data Transformations: map, filter, reduce

Implement `filterEvens(arr)` that returns a new array containing only the even numbers from `arr`.

Sample tests

Input: filterEvens([1,2,3,4,5,6])
Output: [2,4,6]
Input: filterEvens([1,3,5])
Output: []

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Negative evens still qualify; sign does not affect parity.

Learning resources

  • MDN: Array.prototype.filter
Approach & explanation (try first)

filter on even values returns a new array of the evens.

Loading...
⌘/Ctrl + Enter

Run your code to see results.