Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions lib/factorial.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
# Computes factorial of the input number and returns it
# Time complexity: ?
# Space complexity: ?
# Time complexity: On!
# Space complexity: Constant
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure to explain your reasoning behind time and space complexity.

def factorial(number)
raise NotImplementedError
end
raise ArgumentError, "Bad Value" if number == nil
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to also cover bad string integer input, consider:
raise ArgumentError, "Bad Value" if number.is_a?(Integer) == false || number == nil


return 1 if number == 0 || number == 1

minus_one = number - 1
until minus_one == 0
number *= minus_one
minus_one -= 1
end
return number
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work on this method! 🦄 👍

end