Shortest Path Algorithm Leetcode Javascript Problems