Leetcode Breadth First Search Algorithm Javascript Array Splice