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;
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.