Ad
  • Custom User Avatar

    What will happen in if n is 0?

  • Custom User Avatar

    It is a nearly perfect solution.
    You can be a bit concise by using the reduce method instead, because it uses the first value which is identical here.

    fun fact(n: Int): Int {
        return (1..n).reduce { acc, i -> acc * i }
    }
    
  • Custom User Avatar

    yeah sorry lol i was just experimenting with javadoc comments
    edit: also the description was kinda a joke it referenced "this" cuz i removed the this keywords it wasnt about anything else

  • Custom User Avatar

    Btw, I have made the variable names and method names clear to avoid adding comments.

  • Custom User Avatar

    You got a point here. The aspect we often not intuitively think about, but we should care with high standards.
    Often voted best practices are not very explanatory at all. I have a lot to learn too. At the end of the day that's the reason why we are here. Share knowledge. I appreciate your commitment.

  • Custom User Avatar

    sort may not be better all the time. Go for readability and maintainability.

  • Custom User Avatar

    Overall your solution is nice and solid. The comments are obsolete and clutter your code. Use comments only in places where code cannot explain itself. Streams are a fancy way to make things more readable (in most cases) and shorten code. Kind regards Simon