Array Based Leetcode Problems Javascript Substring Until Character