我想把一个数组过滤成一个每第n个项目的array.例如:
fun getNth(array: Array<Any>, n: Int): Array<Any> {
val newList = ArrayList<Any>()
for (i in 0..array.size) {
if (i % n == 0) {
newList.add(array[i])
}
}
return newList.toArray()
}
Is there an idiomatic way to do this using for example Kotlin's .filter() and without A) provisioning a new ArrayList and B) manually iterating with a for/in loop?