Ad

Using the reduce methods

Code
Diff
  • fun fact(n: Int): Int {
        return (1..n).reduce { acc, i -> acc * i }
    }
    
    • fun fact(n: Int): Int {
    • return (1..n).fold(1) { acc, i -> acc * i }
    • return (1..n).reduce { acc, i -> acc * i }
    • }