Shuffle an array
Easy
6
78.3% Acceptance
Write a function suffleArray(arr)
, which takes an array arr
as an argument. This function should shuffle the elements of the array like a deck of cards or in other words, randomly change their positions.
Instructions
- If the input array is empty then return an empty array
- You should shuffle the array in place, do not create a new array
Example test cases
shuffleArray([1, 2, 3, 4, 5]); // Output: [2, 5, 1, 4, 3] shuffleArray(['apple', 'banana', 'orange', 'mango', 'kiwi']); // Output: ['mango', 'kiwi', 'orange', 'banana', 'apple'] shuffleArray([5, 10, 15, 20, 25, 30, 35]); // Output: [20, 5, 25, 15, 10, 30, 35]