+ 1
What does the question mark do in this function, and why is it necessary?
func factorial(n: Int) -> Int { return n == 0 ? 1 : n * factorial(n: n-1) }
3 Respuestas
+ 3
It is a ternary operator. It works like an if statement.
- https://syntaxdb.com/ref/swift/ternary
0
It is an ternary operator similar to if else clause.
Hope this helps☺️☺️.
0
In the Factorial formula, all the positive integers must be multiplied between the number that appears in the formula and the number 1)
Example = 7! = 1 * 2 * 3 * 4 * 5 * 6 * 7 = 5040