Shortest Path Algorithm Leetcode Two Sum Javascript Solution