You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Aug 5, 2021. It is now read-only.
According to the java doc, the java.util.Comparator should do the follwing:
Compares its two arguments for order. Returns a negative integer,
zero, or a positive integer as the first argument is less than, equal
to, or greater than the second.
The current suggested resolution is:
Collections.sort(arrayList, object : Comparator<Int> {
override fun compare(x: Int, y: Int) = y - x
})
which does the opposite - it returns a positive number if the first argument is less than the second, and a negative if the first argument is greater than the second.
I suggest changing the solution to:
Collections.sort(arrayList, object : Comparator<Int> {
override fun compare(x: Int, y: Int) = x - y
})
and the test to:
class N10ObjectExpressionsKtTest {
@Test fun testSort() {
assertEquals(listOf(1, 2, 5), task10())
}
}
The text was updated successfully, but these errors were encountered:
Hi, as I know (not sure just from Kotlin 1.1), all arguments of compare() method are nullable. It means that method should be fun compare(x: Int?, y: Int?): Int. Thus, we should check these arguments for nullability first.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
According to the java doc, the
java.util.Comparator
should do the follwing:The current suggested resolution is:
which does the opposite - it returns a positive number if the first argument is less than the second, and a negative if the first argument is greater than the second.
I suggest changing the solution to:
and the test to:
The text was updated successfully, but these errors were encountered: