Programming in Kotlin: Collections & Lambdas, Episode 8: Challenge: Practice Collections Iteration | raywenderlich.com

Practice iterating over two dimensional collections - matrices, and using exit-early strategies with break and continue.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/33863948-programming-in-kotlin-collections-lambdas/lessons/8

My solution

fun main(args: Array) {
println(sumInteger(listOf(1,2,3,4,5)))
}

fun sumInteger(list : List) : Long {
var sum = 0L
for(i in list) {
sum += i
}
return sum
}

Helllo Dmitry
Firstly, welcome to the course :]

Nice try with the challenge.
Looking at your solution, i can see that sumInteger() returns a Long but what is really expected is an Int since you’re passing in a list of integers when calling it inside the main function.

Feel free to always take a look at my solution after solving a challenge.
You might learn something new.

All the best in your Android journey :+1: