Why my Factorial functions return 1 for any negative value always?
my_factorial(n::Integer)::BigInt = reduce(*, BigInt(1):BigInt(n))
Why my Factorial functions return 1 for any negative value always?
my_factorial(n::Integer)::BigInt = reduce(*, BigInt(1):BigInt(n))
When n
is negative, the range is empty, and reduce(*,)
starts with the multiplicative identity which is 1
.