diff --git a/lib/factorial.rb b/lib/factorial.rb index 6a4a408..6cc2fd2 100644 --- a/lib/factorial.rb +++ b/lib/factorial.rb @@ -1,6 +1,12 @@ # Computes factorial of the input number and returns it -# Time complexity: ? -# Space complexity: ? +# Time complexity: O(n), where n is the value of the number. +# Space complexity: O(n), where n is the value of the number. def factorial(number) - raise NotImplementedError + if number == 0 + return 1 + elsif number.nil? + raise ArgumentError, "This value is nil." + + end + return number * factorial(number - 1) end