I have a problem about adding a letter the end of each word per its word index.
I cannot handle with that. How can I fix it?
Here is my code shown below.
JavaScript
x
for(int i=0;i<sentenceOfArray.length;i++) {
sentenceOfArray[i] = sentenceOfArray[i] + "c";
}
Advertisement
Answer
Here is the solution with the usage of repeat
method.
JavaScript
for(int i=0;i<sentenceOfArray.length;i++) {
sentenceOfArray[i] = sentenceOfArray[i] + "a".repeat(i+1);
}