Kotlin kata1
You will be given an array and a limit value. You must check that all values in the array are below or equal to the limit value. If they are, return true. Else, return false.
You can assume all values in the array are numbers.
起初我觉得这个还算可以吧
fun smallEnough(a : IntArray, limit : Int) : Boolean {
var result :Boolean = true
a.forEach {
f->if (f > limit){
result=false
}
}
return result
}
直到我提交之后
fun smallEnough(a: IntArray, limit: Int) = a.all { it <= limit }
本文来自博客园,作者:ukyo--君君小时候,转载请注明原文链接:https://www.cnblogs.com/ukzq/p/16622574.html