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 }
posted @ 2022-08-24 22:50  ukyo--君君小时候  阅读(26)  评论(0编辑  收藏  举报