I have a function that takes as an argument an array
[["52", ["41", "43", "61", "63"]], ["54", ["43", "45", "63", "65"]]]
"52" is my coin, and ["41", "43", "61", "63"] are possible movement locations for coin "52". The same applies to "54" and ["43", "45", "63", "65"].
In my case cell.innerHTML == '' for locations "41", "43", "45"
The function is behaving correct until freeLocations.push(freeLocation); where its outputs are
["52", "41"], ["52", "43"], ["54", "43"] and ["54", "45"].
However, allFreePostions.push(freeLocations) is outputting only 3 arrays: ["52", "41"], ["52", "43"] and ["54", "45"]. ["54", "43"] is missing.
strangely if I edit freeLocations.push(freeLocation, j) just for debugging, the missing array shows up in allFreePostions.push(freeLocations).
Am I missing anything here?
function checkFreeLocations(coins){
let allFreePostions = [];
let dangerPosition = [];
for (let i = 0; i < coins.length; i++){
coin = coins[i][0];
positions = coins[i][1];
for (let j = 0; j < positions.length; j++){
let freeLocations = [];
let cell = document.getElementById(positions[j]);
if (cell.innerHTML == ''){
freeLocation = positions[j];
freeLocations.push(coin);
freeLocations.push(freeLocation);
allFreePostions.push(freeLocations);
}
}
}
}
checkFreeLocations([["52", ["41", "43", "61", "63"]], ["54", ["43", "45", "63", "65"]]])