factorial function

int factorial(
  1. int n
)

Calculates the factorial of a number. Throws for negative inputs.

Implementation

int factorial(int n) {
  if (n < 0) throw ArgumentError('Negative numbers not allowed');
  return n <= 1 ? 1 : n * factorial(n - 1);
}