Arrays & Iterables

Fisher-Yates Array Shuffle

mediumJS SpecificJS / TS3 tests

Problem Statement

Implement `shuffle(array)` that returns a new randomly shuffled copy of `array` using the Fisher-Yates (Knuth) algorithm with uniform distribution O(n).

Examples

Example 1:
const original = [1, 2, 3, 4, 5];
const shuffled = shuffle(original);
console.log(shuffled.length); // 5
console.log(shuffled.sort()); // [1, 2, 3, 4, 5]
JavaScript & TypeScript starter code included
Run this as a live interview

Practice solo

3 test cases. No second person needed.

Get new interview exercises

Practice problems and review drills, sent when we publish new ones. No spam.

Unsubscribe anytime. We never share your address.