이 루프를 foreach, map 또는 Scala의 다른 함수와 같은 일부 함수로 단순화하려면 어떻게해야합니까? hitsArray를 필터 shipList.filter 안에 넣고 싶습니다. 어디서든 사용하지 않는 당신이 shipSize = shipList.length
를 호출하는 이유한 줄로 스칼라 루프 단순화
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
}
'발 hitsArray : 배열 [문자열 청소기 경우
shipList
비록이미 모두 소문자입니다 ] = T.split (""); for (hit <- hitsArray) {shipSize = shipList.length; shipList = shipList.filter (! _. equalsIgnoreCase (hit))}; if (shipList.length == 0) {shipSunk = shipSunk + 1} else if (shipList.length