Implement Array.join

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.join

Approach

Iterate through the array, concatenating each element to a result string with the separator inserted between elements. Handle the default comma separator when none is provided, and treat null/undefined values as empty strings to match native behavior.

Complexity Analysis

Time
O(n)
Space
O(n)

Pattern

Array Polyfill

Why It Works

String concatenation with a conditional separator between elements reproduces the native join behavior, including the edge case of skipping null and undefined values.

Updated Mar 2026