Array Based Leetcode Problems Javascript Substring Index