function repeatedString(s, n) {
const regex = new RegExp(/a/gi);
const match = s.match(regex) || [];
const length = match.length;
if (length) {
const ratio = Math.floor(n / s.length);
const remain = n - (ratio * s.length);
let x = 0;
for(let i = 0; i < remain; i++) {
if (s[i] === 'a') x++;
}
return (ratio * length) + x;
}
return 0;
}
repeatedString('aba', 10);
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (0)