Expressive Words LeetCode solution in JavaScript
1/**2* @param {string} s3* @param {string[]} words4* @return {number}5*/6var expressiveWords = function (s, words) {7let arr = [];8let curr = 0;9while (curr < s.length) {10let count = 1;11while (s[curr] === s[curr + 1]) {12count++;13curr++;14}15arr.push([s[curr], count]);16curr++;17}18let ans = 0;19for (let charArr of words) {20let idx = 0;21let i = 0;22let flag = true;23if (charArr.length > s.length) continue;2425while (i < charArr.length) {26let count = 1;27while (charArr[i] === charArr[i + 1]) {28i++;29count++;30}31if (32arr[idx][0] !== charArr[i] ||33arr[idx][1] < count ||34(arr[idx][1] < 3 && arr[idx][1] !== count)35) {36flag = false;37break;38}39idx++;40i++;41}42if (idx !== arr.length) flag = false;43if (flag) ans++;44}45return ans;46};