loading...

Discussion on: Look ma', without loops!

Collapse
qwewqa profile image
qwewqa

I believe you may be able to use the count function instead of the filter function to directly get the result.

Collapse
chrisvasqm profile image
Christian Vasquez Author

Hmmm 🤔

I'll check it out and update the post!

EDIT:

You are totally right 😲

The filter way:

val belowAverage = students.filter { it.score < average }.size

The count way:

val belowAverage = students.count { it.score < average }

🎉🎉🎉