Count The Repetitions LeetCode solution in JavaScript
1/**2* @param {string} s13* @param {number} n14* @param {string} s25* @param {number} n26* @return {number}7*/8var getMaxRepetitions = function (s1, n1, s2, n2) {9const len1 = s1.length;10const len2 = s2.length;11let count1 = 0; // Number of times s2 can be formed from s112let count2 = 0; // Number of times str2 = [s2, count2] can be formed from str1 = [s1, count1]13let i = 0; // Pointer for s114let j = 0; // Pointer for s215while (count1 < n1) {16if (s1[i] === s2[j]) {17j++;18if (j === len2) {19j = 0;20count2++;21}22}23i++;24if (i === len1) {25i = 0;26count1++;27}28}29return Math.floor(count2 / n2);30};