Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save philsof/73d9f4bbbb6d75db21ef to your computer and use it in GitHub Desktop.
Save philsof/73d9f4bbbb6d75db21ef to your computer and use it in GitHub Desktop.

Nice work on this one. Here are my notes on your code:

  • Your factorial_iterative method does the job concisely, but not as concisely as possible. Specifically, your if condition only handles zero, but not 1. Since you already have if n == 0 you might as well catch 1 with this line also, so a good refactor would be if n <= 1. That way, if n is 1 you don't end up creating an array of [1] and running reduce on it.
  • Your reduce is super sharp. Sweet!
  • Your factorial_recursive method is short and sweet, and it takes care of 0 and 1 all in one line.
  • Watch out though: you have a p call inside your method. This method should not concern itself with printing the value, only with returning the value. It looks like you are already aware of this because you also have a p call in your runner code (which is where it should be).

Any questions, let me know.

-Phil

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