I'm trying to convert the array = ["A", "B", "C", "D"]
into array = ["A", "BB", "CCC", "DDDD"]
. If you compared the arrays, you'll notice that the letters inside the second array have extra same letters in each position. Here is my code below. I used the for loop because I wanted to use the increment inside the for loop. I don't even know if map() method can do the same so I went with for loop. However, when I checked, it didn't show the result that I wanted. What did I miss?
function accum(s) {
// your code
let accArray = s.toUpperCase().split("");
for (let i = 1; i < accArray.length; i++) {
accArray[i].repeat(i + 1);
}
console.log(accArray);
}
accum("abcd")