Wie vereinfache ich diese Schleife zu einer Funktion wie foreach oder Karte oder andere Sache mit Scala? Ich möchte hitsArray innerhalb dieses Filters shipList.filter setzen.Simplify Scala Schleife zu einer Zeile
val hitsArray: Array[String] = T.split(" ");
for (hit <- hitsArray) {
shipSize = shipList.length
shipList = shipList.filter(!_.equalsIgnoreCase(hit))
}
if (shipList.length == 0) {
shipSunk = shipSunk + 1
} else if (shipList.length < shipSize) {
shipHit = shipHit + 1
}
'val hitsArray: Array [String ] = T.split (""); for (hit <- hitsArray) {shipSize = shipList.length; shipList = shipList.filter (! _. equalsIgnoreCase (hit))}; if (shipList.length == 0) {shipSunk = shipSunk + 1} sonst if (shipList.length