November 12th, 2024
What's missing in this code?
shuffle('orange'); // oarnge
shuffle('code'); // coed
shuffle('javascript'); // jcarviapst
shuffle('hello world'); // h ewlolrol do
function shuffle(baseString) {
let arr = baseString.split('');
const func = (array) => {
let mid =
(array.length / 2);
let shuffled = [];
for (let i = 0, j = mid; j < array.length; i++, j++) {
shuffled.
(array[i], array[j]);
}
return array.length % 2 === 0
? shuffled
:
(array[mid - 1]);
};
arr = func(arr);
return arr.join('');
}
Type or select from these options