What's missing in this code?
const arr1 = [10, 20, 30, 40];
funcN(arr1, 1); // [10, 30, 20, 40]
funcN(arr1, 2); // [10, 20, 30, 40]
funcN(arr1, 3); // [10, 30, 20, 40]
const arr2 = [1, 2, 3, 4, 5, 6];
funcN(arr2, 1); // [1, 4, 2, 5, 3, 6]
funcN(arr2, 2); // [1, 5, 4, 3, 2, 6]
funcN(arr2, 3); // [1, 3, 5, 2, 4, 6]
const arr3 = [1, 1, 1, 2, 2, 2];
funcN(arr3, 1); // [1, 2, 1, 2, 1, 2]
funcN(arr3, 2); // [1, 2, 2, 1, 1, 2]
funcN(arr3, 3); // [1, 1, 2, 1, 2, 2]
function funcN(arr, times) {
let shuffled = arr.
;
for (let i = 0; i < times; i++) {
shuffled = func(shuffled);
}
return shuffled;
}
function func(arr) {
const mid = Math.floor(arr.length / 2);
const left = arr.slice(0, mid);
const right = arr.slice(
);
const shuffled = [];
for (let i = 0; i < left.length; i++) {
shuffled.push(
);
if (
!== undefined) {
shuffled.push(right[i]);
}
}
return shuffled;
}
Type or select from these options