The repeatedString function takes a string and calculates the total number of occurrences of each word in the string and stores it in a variable. It then subtracts the length of the slice from the total number of occurrences to get the number of letters in the string that have been repeated n times.
function repeatedString(s, n) {
let occurances = s.split("a").length - 1;
let max = Math.floor(n / s.length);
let totalAs = occurances * max;
totalAs += s.slice(0, n % s.length).split("a").length - 1;
return totalAs;
}