我收到“变异运算符的左侧不可变”..<“返回不可变值”错误
我阅读了关于变异值的另一篇文章,但我无法弄清楚这些解决方案是如何应用的。
代码(和评论):
//populate array of 3 random numbers using correct answer and 2 incorrect choices
func insertIntoArray3(_ randomNumber: Int) -> Int {
for intJ in 0 ..< 2 += 1{
if arrayIndex != 3 {
checkIfExists(randomNumber)
if ifExists {
let randomNumber = 1 + random() % 10
insertIntoArray3(randomNumber)
} else {
array3[arrayIndex] = (randomNumber)
arrayIndex = arrayIndex + 1
}
}
}
return randomNumber
}
Run Code Online (Sandbox Code Playgroud)
修订代码:
//populate array of 3 random numbers using correct answer and 2 incorrect choices …Run Code Online (Sandbox Code Playgroud)