Nice work on this one. Here are my notes on your code:
- Your
factorial_iterativemethod does the job concisely, but not as concisely as possible. Specifically, yourifcondition only handles zero, but not 1. Since you already haveif n == 0you might as well catch1with this line also, so a good refactor would beif n <= 1. That way, ifnis1you don't end up creating an array of[1]and runningreduceon it. - Your
reduceis super sharp. Sweet! - Your
factorial_recursivemethod is short and sweet, and it takes care of0and1all in one line. - Watch out though: you have a
pcall 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 apcall in your runner code (which is where it should be).
Any questions, let me know.
-Phil