re: Factorial Algorithm: ES5 & ES6 JavaScript Solutions VIEW POST


I like how this shows both ES5 and ES6 solutions, but since at the beginning of the article you mentioned it is common in white-boarding exercises, it might have been interesting or useful to also talk about how to improve the efficiency of the algorithms. Such as using a dictionary/hashmap to store previously computed values. Or perhaps you plan on doing that in the future?

I mention it, because I have actually gotten asked this question in one of my first white boarding interviews a few years ago. Initially, I wrote down something similar to the ES5 approach but in python. The interviewer then said "ok but what if there isn't an upper limit on your input, what if someone tried to find the factorial of a thousand or ten thousand, etc?" So I did have to make it more efficient using a dictionary. Sometimes interviewers are looking for this thought process and improvement.


Hi Jared,
thank you for the comment. We are still in the #beginner section here and I would like to breakdown the basic most common algorithms first.

However, thank you for the suggestion, I will take note and maybe do the breakdown of more advanced factorial solution later.
If you feel like solving more advanced factorial (in JS?) take a look at this HackerRank challenge.

Also, thank you for sharing the real-life experience, always good to know what can one expect on an interview.

code of conduct - report abuse