I'm trying to solve this exercise which goal is to give me a string that has to be turned into another string. The characters of the new string are repeated like in the example below.
Example:
accum("abcd"); // "A-Bb-Ccc-Dddd"
I wrote the following code:
function accum(s) {
counter = 0;
for (var i = 0; i < s.length; i++) {
return s[i].toUpperCase() + s[i].repeat(counter) + "-";
counter += 1;
}
}
When I try to run a sample test such as ZpglnRxqenU I get this error:
Expected: 'Z-Pp-Ggg-Llll-Nnnnn-Rrrrrr-Xxxxxxx-Qqqqqqqq-Eeeeeeeee-Nnnnnnnnnn-Uuuuuuuuuuu', instead got: 'Z-'.
Apparently the problem is linked to the loop which is not working, but I can't figure out why.