Your code gets the job done and passes all the tests. Nice! Some notes:
- Your code is concise and clear. And it works. Good stuff.
- Heads up: This line of code is being made more complicated by this line of code. Specifically, when you create your array on line 3, you are using
...
(three dot operators), which tells Ruby to create an array that does not include the starting and ending values (thus,1
andn
are not included in the array). Because of this, you have to addn
to yourreduce
arguments, sincen
is not in your array.
You can simplify your code in two ways. First, by changing your array declaration to:
array = (1..n) # notice the two dot operators, not three
Then, since n
is now in array
, you can simplify your reduce
method to:
array.reduce(:*)
- Be sure to delete code that is not needed from your final product.
- Be sure to keep your formatting uniform by tightening up your final code. Specifically, delete these two empty lines.
Good work! Any questions let me know.
-Phil