Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fun main() {
- var list = (1..10).toList()
- val sum = list.customSum { it % 2 == 1 }
- println("The sum is: $sum")
- }
- fun List<Int>.customSum(sumFunction: (Int) -> Boolean): Int {
- var result = 0;
- for(i in this) {
- if (sumFunction(i)) {
- result += i
- }
- }
- return result
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement