You are viewing a single comment's thread. Return to all comments →
let length =s.length,count=1,repeactChar='a'; let repetWord = Math.floor(n/length); let remainderChar = n%length;; for(let i = 0; i < length; i++){ if(repeactChar == s[i]) count++; } count = count * repeatWord; for(let j = 0; j < remainderChar; j++){ if(repeactChar ==s[j]) count++; } return count
Seems like cookies are disabled on this browser, please enable them to open this website
Repeated String
You are viewing a single comment's thread. Return to all comments →
JavaScript Solution
let length =s.length,count=1,repeactChar='a'; let repetWord = Math.floor(n/length); let remainderChar = n%length;; for(let i = 0; i < length; i++){ if(repeactChar == s[i]) count++; } count = count * repeatWord; for(let j = 0; j < remainderChar; j++){ if(repeactChar ==s[j]) count++; } return count