Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Array.from with Map

Working With Arraysmedium

Course · Section 11: Working With Arrays · Lecture 174: More Ways of Creating and Filling Arrays

Implement `rangeSquares(n)` returning `[0, 1, 4, 9, ...]` of length `n` using `Array.from` with a map callback.

Sample tests

Input: rangeSquares(3)
Output: [0,1,4]
Input: rangeSquares(1)
Output: [0]

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • new Array(n) creates empty slots that map skips.
Approach & explanation (try first)

Array.from with a length and a map callback generates and transforms in one step.

Loading...
⌘/Ctrl + Enter

Run your code to see results.