Pather problem given to me for a job interview. (attempt at a JS version)