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 }
    }