oday
07/23/2021, 9:33 AMfor (i in 1 until array.size)
the best equivalent to this?
for num in array[1:]
Roukanken
07/23/2021, 9:38 AModay
07/23/2021, 9:38 AM1:
to mean from 1 until the end
Roukanken
07/23/2021, 9:41 AMdrop(1)
function, which copies whole iterable except the first x members
(unless it's a sequence, in sequence it works š)for (num in array.drop(1))
would work, but it would impact performance a bit, against the python versionoday
07/23/2021, 9:46 AMRoukanken
07/23/2021, 9:47 AMarray.asSequence()
.drop(1)
.map { ... }
.forEach { ... }
Klitos Kyriacou
07/23/2021, 10:08 AMok so the one I suggested in the beginning i guess is the most readable
I think for (num in array.drop(1))
is more readable because you can use num
directly for each element, instead of array[i]
. But it's a matter of opinion; do what's more readable for you and your colleagues or whoever reads your code.Paul Griffith
07/23/2021, 3:50 PMval array = intArrayOf(1, 2, 3)
array.sliceArray(1 until array.size)
on the JVM at least, sticking with arrays instead of dropping to sequences or lists is going to be a massive performance gainoday
07/23/2021, 5:51 PM