Your Submissions
You haven't submitted any code for this challenge yet. Solve the problem by passing all the test cases, and your submissions will appear here.
xxxxxxxxxx
25
// Shuffle function implementation - fill in your code!
function shuffle(arr) {
// fill this in
}
const arr = [1, 2, 3, 4];
const permutations = [
[1, 2, 3, 4], [1, 2, 4, 3], [1, 3, 2, 4], [1, 3, 4, 2], [1, 4, 2, 3], [1, 4, 3, 2],
[2, 1, 3, 4], [2, 1, 4, 3], [2, 3, 1, 4], [2, 3, 4, 1], [2, 4, 1, 3], [2, 4, 3, 1],
[3, 1, 2, 4], [3, 1, 4, 2], [3, 2, 1, 4], [3, 2, 4, 1], [3, 4, 1, 2], [3, 4, 2, 1],
[4, 1, 2, 3], [4, 1, 3, 2], [4, 2, 1, 3], [4, 2, 3, 1], [4, 3, 1, 2], [4, 3, 2, 1]
];
// Shuffle the array
shuffle(arr);
// Validate the shuffled array
const isValidPermutation = permutations.some(permutation => JSON.stringify(permutation) === JSON.stringify(arr));
if (isValidPermutation) {
console.log('The shuffled array is a valid permutation:', arr);
} else {
console.log('Something went wrong! The shuffled array does not match any of the valid permutations.');
}
OUTPUT
Results will appear here.