Write function strLetterCount and return new string with the characters followed by the count

function strLetterCount (word){
   let results = ""
   for(let i = 0; i < word.length; i++) {
      let charAt = word.charAt(i)
      if (!results.includes(charAt)) // <----------------------
      {
        let count = 0

        results += charAt

        for (let j = 0; j < word.length ; j++)
        {
           if(word.charAt(j) === charAt)
           {
              count++
           }
        }
        results += count
       }
   }
   return results;
}

console.log(strLetterCount("coconut"));

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top