Last active
December 11, 2015 16:18
-
-
Save pjlowry/4626419 to your computer and use it in GitHub Desktop.
big numbers!!!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def factorial(number) | |
if number < 0 | |
"You can't take the factorial of a negative number" | |
elsif number == 0 | |
1 | |
else | |
(2..number).inject (:*) | |
end | |
end | |
puts "'#{factorial(0)}' should equal '1'." | |
puts "'#{factorial(5)}' should equal '120'." | |
puts "'#{factorial(-2)}' should equal 'You can't take the factorial of a negative number'." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment