Skip to content
This repository was archived by the owner on Aug 5, 2021. It is now read-only.
This repository was archived by the owner on Aug 5, 2021. It is now read-only.

Not quite perfect answer in "Object expressions" and "SAM conversions" online koans #155

@praetoriandroid

Description

@praetoriandroid

Sorry, if this is the wrong place - the issue is related to online koans (http://try.kotl.in), not these one. But I could not find the better place for this.

Online koans are really great. And "Show answer" button is very handy: it helps to check out, is your solution the best for the kotlin style.

But in two tasks below you give not quite perfect answers. The suggested solution for comparing two Ints is "y - x":
https://try.kotlinlang.org/#/Kotlin%20Koans/Introduction/Object%20expressions/Task.kt
https://try.kotlinlang.org/#/Kotlin%20Koans/Introduction/SAM%20conversions/Task.kt

It works well with your test data set, but it's really bad idea to do this if, say, x = Int.MIN_VALUE and y = -1. And of course the correct solution here is "y.compareTo(x)".

I understand that this is not related to the kotlin koans directly. But someone can use the wrong pattern and get a bug. So please fix this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions