Array Based Leetcode Problems Javascript Substring Method