I am able to shuffle an array with this function
function getBadlyShuffledList(list) {
var length = list.length;
var i;
var j;
while (length) {
i = Math.floor(Math.random() * length--);
j = list[length];
list[length] = list[i];
list[i] = j;
}
return list;
}
console.log(getBadlyShuffledList([1,2,3,4,5,6]));
The problem is I need to leave the index's that are divisible by two in their places. I tried using an if statement and it get's the index if it is 2 or 4, but then I don't know what to do to make it stay put.
For example if I have an array [1, 2, 3, 4, 5, 6] When shuffled, 3 and 5 should remain put. ex; [2, 4, 3, 1, 5, 6] How do I go about doing this?