From e2c75b9219c9b2b30abfec8ca4401bc22fb44299 Mon Sep 17 00:00:00 2001 From: Ariana Bray Date: Mon, 8 Apr 2019 23:18:11 -0700 Subject: [PATCH] solved factorial and tests --- lib/factorial.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) 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