I have two Arrays they both have the same size and look like this:
a= [ 1, 2, 3, 2]
and b = ['this', 'is', 'my', 'good example']
.
Array a[i] defines how often the value of b[i] i want to write to a new Array. For my example the result would be c = ['this', 'is', 'is', 'my', 'my', 'my', 'good example', 'good example']
.
I tried around with String.repeat but i dont know how to get it to an Array
3
Answers
I think this solution will suit you
You could just do a loop inside another loop to achieve that
I agree that
flatMap
is ideal for this task, as answered by @lvjonok