Breadth First Search Algorithm Leetcode Problems Javascript