You are viewing a single comment's thread. Return to all comments →
I had the same idea but whithout otimization
function filterAs(arr) { let result = 0; for (let letter of arr) { if (letter === 'a') { result++ } } return result } function repeatedString(s, n) { const lengthString = s.length const numberDivision = Math.floor(n / lengthString) const numberOfAs = filterAs(s) const remainder = n - (numberDivision * lengthString) if (remainder === 0) { return numberDivision * numberOfAs } let moreAs = filterAs(s.substring(0, remainder)) return numberDivision * numberOfAs + moreAs }
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 →
I had the same idea but whithout otimization