Reputation: 624
I'm pretty new in Scala and trying to change the values in a multi dimension Array in the Scala way if there is such thing :)
Let's see the problem:
val table = Array.fill(5, 5){1}
and I'm trying to change every 1 to 5
for (i <- 0 until table.length) {
for (j <- 0 until table(i).length) {
table(i)(j) = 5
}
}
But I think there will be some other (more functional way) to do the same thing.
Thank you!
Upvotes: 0
Views: 44
Reputation: 21700
val table = List.fill(5, 5){1}
val all5 = table.map(_.map(_ => 5))
Upvotes: 6