Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Task requires using "spread operator" but there's no reasonable way to use that here and none of the top solutions have it. I spent a while trying to figure out where to use it before finally "giving up" and submitting my solution that used everything else. Made the problem frustrating/unenjoyable.
FYI this won't work in strict mode without let [a,b]. See my fork.
I think the count(n)=count(s) solution is cleaner and slightly more efficient. It makes 41 comparisons whereas this one makes 43 (2 more in last line) and creates var x,y and sets them to 0.
This comment is hidden because it contains spoiler information about the solution
This is wrong. Test cases need to be fixed. n: 5, w: 5, s:0, e: 0 would return True even though you would be 10 steps away from where you started.
@oddone Your solution is incorrect (bad test cases). Consider n:0, e:5, s:0, w:0.
Wrong Location:
(0,5) != (0,0)
& Wrong Distancelen(walk) != 10
but returnsTrue
!I fixed it in a fork. Note that "n" is "y -+ 1". Two mistakes.
@mmircevska Yes it would return
False
immediately! Usingand
is as effective as yourif
test.and
&or
are very efficient.False and whatever
will returnFalse
before looking atwhatever
.True or whatever
will returnTrue
before looking atwhatever
.