I'm trying to solve a problem using my very limited knowledge of Javascript.
I've tried to build a way to count the number of times a particular letter appears in an array and compare it to the number of times another letter appears in the same array.
I'm able to pass 3 out 4 tests and have re written the code many times trying as many methods as I know.
I realize that what I've done is not efficient...just working on problem solving with a weeks worth of skills.
Appreciate any input. Thanks.
function isValidWalk(walk) {
var north = new Object ();
var south = new Object ();
var east = new Object ();
var west = new Object ();
for (var i = 0; i <walk.length; i++){
if (walk[i] == "n")
{north.input = "x"}
}
for (var i = 0; i <walk.length; i++){
if (walk[i] == "s")
{south.input = "x"}
}
for (var i = 0; i <walk.length; i++){
if (walk[i] == "e")
{east.input = "x"}
}
for (var i = 0; i <walk.length; i++){
if (walk[i] == "w")
{west.input = "x"}
}
if (north.input == south.input && east.input == west.input && walk.length==10) {
return true;
}
else {
return false;
}
}