Maximum Repeating Substring Leetcode Javascript Question