Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Squares of Even Numbers

A Closer Look at Functionsmedium

Course · Section 10: A Closer Look at Functions · Lecture 137: First-Class and Higher-Order Functions

Implement `evenSquares(nums)` returning the squares of just the even numbers, using `filter` then `map`.

Sample tests

Input: evenSquares([1,2,3,4])
Output: [4,16]
Input: evenSquares([1,3])
Output: []

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Squaring before filtering, which changes which values are even.

Learning resources

  • MDN: Array iteration methods
Visualize this concept: Higher-Order Functions →
Approach & explanation (try first)

Chaining filter then map keeps only evens and squares them, a common transform pipeline.

Loading...
⌘/Ctrl + Enter

Run your code to see results.