You are viewing a single comment's thread. Return to all comments →
nice solution, very similar to mine!
countAs looks a bit uglier, but I tried to avoid transforming to array.
countAs
Also, I think it is almost the same, but you could use % for calculating the rest
%
rest
function repeatedString(s, n) { countAs = (s, index) => { let count = 0; while (index >= 0) { if (s[index] == 'a') count++; index--; } return count; }; if (n <= s.length) { return countAs(s, n - 1); } else { const parts = Math.floor(n / s.length); const rest = n % s.length; return countAs(s, s.length - 1) * parts + countAs(s, rest - 1); } }
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 →
nice solution, very similar to mine!
countAs
looks a bit uglier, but I tried to avoid transforming to array.Also, I think it is almost the same, but you could use
%
for calculating therest