Javascript Loop Array And String Problems Leetcode