Ad
  • Custom User Avatar

    Your isValidWalk function doesn't ever return a value, so it implicitly returns undefined. which is falsey in JavaScript. That's why you passed the tests that expected false. Your return statements both happen inside the callback function you're passing to map, so map will be returning an array of boolean values; one for each item in walk.

    The callback function to map is called once for every item in walk. That means that you create the four arrays to track directions for every item in walk, insert a value into only one of them, then check that the lengths are equal. This will never be true, because 3 of them will have 0 length and one will have a single item each time it is run. You'll need to declare the 4 arrays before you call map, and you'll also need to move the length checking and final return to only happen after map completes. Then, since you're not using the return value of map, it would make more sense to change it to forEach instead.

    As a final note, the b parameter to the callback function is the index of the item in the walk array, so it can never be equal to a for this particular kata.