I have the following problem with a 'for in' loop: it does not want to recognize the elements of the array. I tried to see the elements after calling the 'for in' with the console.log, but it returns 0.
function isValidWalk(walk) {
console.log(walk.length);
if (walk.length ===10) {
var WalkN=[];
var WalkS=[];
var WalkE=[];
var WalkW=[];
console.log(walk);
for (var elemento in walk) {
console.log(elemento);
console.log(walk);
switch (elemento) {
case 'n':
WalkN.push(elemento);
break;
case 's':
WalkS.push(elemento);
break;
case 'e':
WalkE.push(elemento);
break;
case 'w':
WalkW.push(elemento);
}
console.log( WalkN,WalkS,WalkE,WalkW);
if (WalkN.length===WalkS.length && WalkE.length===WalkW.length) {
return true
}
else { return false }
}
}
else {
return false
}
}
isValidWalk(['n','s','n','s','n','s','n','s','n','s'])