Implement Array.map

Easy
Code
Loading editor...
Tap Analyze to see visualization
Variables

Run code to see variables

Output

Console output will appear here

Press Space to start to step? all shortcuts

Solution Guide: Implement Array.map

Approach

Iterate through the array, apply the callback to each element with (value, index, array) arguments, and push each transformed result into a new array. The original array is never modified, preserving immutability.

Complexity Analysis

Time
O(n)
Space
O(n)

Pattern

Array Polyfill

Why It Works

Map creates a 1:1 transformation: every input element produces exactly one output element. The callback receives the current value, index, and original array, matching the native Array.prototype.map signature.

Updated Feb 2026