Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save philsof/7baf997f6712631b5125 to your computer and use it in GitHub Desktop.
Save philsof/7baf997f6712631b5125 to your computer and use it in GitHub Desktop.
Code review: branch pair-superboyblue for algorithm-drill-factorial-challenge

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 and n are not included in the array). Because of this, you have to add n to your reduce arguments, since n 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(:*)

Good work! Any questions let me know.

-Phil

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment