“Field Trip” fun…
I hate getting tripped up on silly interview questions, and I usually always rework them afterwards to see what brief moment of dumbness I was suffering during the interview.
On a “field trip” I took recently just for fun b/c of who it was, I had a problem presented like this, with a jsFiddle link to my current solution below.
GRRRR at how easy this was in thought after the interview…
An interview question, to create a generic function that will give a path for cursor animation on a “search menu” that is displayed like:
A B C D E
F G H I J
K L M N O
P Q R S T
U V W X Y
Z
With a path given like “R!L!DDDRRRR!” when searching for “BAT”.
The problem assumptions were that you are always dealing with uppercase letters, no special characters, no spaces, etc. The beginning always starts at ‘A’. You are also given a dynamic width (to worry about), so your function can traverse any size menu. I got tripped up on this after getting barraged with a bunch of core JS language questions, so here’s a stab at the solution, minus some additional work to not traverse boundaries (outside the matrix or in places where there are no selectable letters).