Created
June 12, 2012 21:15
-
-
Save pzaich/2920180 to your computer and use it in GitHub Desktop.
Injection methods
This file contains hidden or 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) | |
| product = 1 | |
| if number != 0 | |
| (1..number).each do |operand| | |
| product *= operand | |
| end | |
| end | |
| product | |
| end | |
| def factorial(number) | |
| product = 1 | |
| if number != 0 | |
| (1..number).each { |n| product *= n } | |
| end | |
| product | |
| end | |
| def factorial(number) | |
| (1..number).inject(1) { |product, n| product * n} | |
| end | |
| def factorial(number) | |
| (1..number).inject(1) do |product, n | | |
| puts "----- Iteration #: #{n} ---------" | |
| puts "product = #{product}" | |
| puts "factor = #{n}" | |
| puts "New Product = #{product*n}" | |
| puts | |
| product * n | |
| end | |
| end | |
| def factorial(number) | |
| (1..number).inject(1, :*) | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment