Skip to content

Latest commit

 

History

History
21 lines (15 loc) · 1.89 KB

File metadata and controls

21 lines (15 loc) · 1.89 KB

shuffle medium #javascript

by Pawan Kumar @jsartisan

Take the Challenge

Implement a shuffle function that takes an array as input and returns a new array with its elements shuffled in random order. The original array should remain unmodified.

Requirements:

  1. The function should be named shuffle.
  2. The function should take one argument:
    • An array of elements to be shuffled.
  3. The function should return a new array with the elements shuffled in random order.

Example Usage:

const arr = [1, 2, 3, 4, 5];
const shuffledArr = shuffle(arr);
console.log(shuffledArr); // [3, 5, 1, 4, 2] (example, actual result will vary)
console.log(arr); // [1, 2, 3, 4, 5] (original array remains unchanged)

Back Share your Solutions Check out Solutions