diff --git a/lib/factorial.rb b/lib/factorial.rb index 6a4a408..9baf1f8 100644 --- a/lib/factorial.rb +++ b/lib/factorial.rb @@ -1,6 +1,54 @@ # Computes factorial of the input number and returns it -# Time complexity: ? -# Space complexity: ? +# Time complexity: Linear or O(n) where n is the number input +# Space complexity: Constant or O(1), will have the same number of variables no matter the size of the input + def factorial(number) - raise NotImplementedError +return 1 if number == 0 +if number == nil + raise ArgumentError, "Enter an integer" +end +a = 1 +b = number +while a < number + b = b * (number - a) + a += 1 +end +return b end + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +