Leetcode Breadth First Search Algorithm Javascript Foreach Continue