Last active
July 2, 2024 05:03
-
-
Save jonikarppinen/139a2b7222d7da6454b8beef54219803 to your computer and use it in GitHub Desktop.
onlyEvenInt in Kotlin ("Write a function that takes an array of integers as an input, and returns a new array containing only even integers, sorted.")
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Run it at play.kotlinlang.org | |
fun onlyEvenInt(numbers: List<Int>) = numbers.filter { it % 2 == 0 }.sorted() | |
fun main() { | |
println(onlyEvenInt(listOf(1, 2, 3, 4, 5, 6, 7))) | |
println(onlyEvenInt(listOf(6, 7, 1, 2, 3, 4, 5))) | |
println(onlyEvenInt(listOf(1, 3, 5, 7))) | |
println(onlyEvenInt(listOf(-2, -3, -4, 0))) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Being on JVM, using lists is idiomatic. But could use arrays just as well.