Seems like such a simple task, but I can't seem to get it right. The idea is to have an array of 8 other arrays, each containing sets of cards (although in this case, they just have random numbers). Depending on whether passDirection is set to -1 or 1, each array should shift by one position, creating a shifting effect for the playerList values.
However, instead of shifting properly, all arrays are getting replaced with the value at index 0, except for the first one. How do I correct this issue?
var playerList = new Array;
var passDirection = -1;
for(i = 0; i < 8; i++) {
playerList.push([playerList.length,i]); // Populating Arrays with random data
}
for (i=0; i< playerList.length; i++) {
console.log(i + ": " + playerList[i]); // Checking initial values
}
for(q=0; q < 5; q++){ // Repeating the process 5 times
var bufferArray = playerList[0];
for(i = 0; i < playerList.length && i > (playerList.length * -1); i += passDirection) {
var catcher = i;
var passer = catcher - passDirection;
if (catcher < 0) {
catcher = catcher + playerList.length;
}
if (passer < 0) {
passer = passer + playerList.length;
} else if (passer >= playerList.length) {
passer = passer - playerList.length;
}
if (passer == 0) {
playerList[catcher] = bufferArray;
} else {
playerList[catcher] = playerList[passer];
}
}
for (i=0; i< playerList.length; i++) {
console.log(i + ": " + playerList[i]);
}
console.log("...");
}