Help with Kotlin distinctBy() function

Hi everyone, I have a question on using the destinctBy() function from the Kotlin library.

Below is my (simple) code with the results. I expected the code to print the one unique even number but instead it prints the first number AND the one unique even number. Since the first number is odd and it definitely is not unique in the array, I am wondering why this function does not work?

fun main() { var arrayOfInts = arrayOf(3,5,7,9,1,2,11,13) var oddBallInt = arrayOfInts.distinctBy {it % 2} println(oddBallInt) } 

Result is: [3, 2]

If I place the number 2 in the first position and any other of the odd numbers in the second position (like 11) it will return: [2, 11]

Can anyone clear this up for me?

Thanks

Claven

submitted by /u/ClavenEstine
[link] [comments]