is there a more kotlin way to do the following: (i...
# announcements
l
is there a more kotlin way to do the following: (interate a list, selecting an item and the item before it and performing an operation on those two elements):
Copy code
fun totalDistance(aList: List<Location>) : Double{
            var total: Double = 0.0
            for(x in 1..aList.size-1) {
                total += distance(aList[x], aList[x-1])
            }
            return total
        }
l
oh nice, thanks looks like exactly what I was looking for
t
just a FIY. there is also the more generic form of window, which is handy from time to time. https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/windowed.html
👍 1