Count Number Of Substrings Leetcode Javascript