Pathfinding in JS