val inArray = Array("a", "b", "c", "d")
// ...
val outArray = Array("a1", "a2", "a3", "b1", "b2", "b3", "c1", "c2", "c3", "d1", "d2", "d3")
How to map inArray
to outArray
?
The idea is to iterate through inArray
yielding 3 elements (by concatenating an index in this example) from each of its elements.
You can do that with flatMap
.
inArray.flatMap(c => (1 to 3).map(c+))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With