Looking for a really fast implementation of the factorial function in JavaScript. Any suggestions?
Looking for a really fast implementation of the factorial function in JavaScript. Any suggestions?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can search for (1…100)! on Wolfram|Alpha to pre-calculate the factorial sequence.
The first 100 numbers are:
If you still want to calculate the values yourself, you can use memoization:
Edit: 21.08.2014
Solution 2
I thought it would be useful to add a working example of lazy iterative factorial function that uses big numbers to get exact result with memoization and cache as comparison
I assume you would use some kind of closure to limit variable name visibility.
Ref: BigNumber
Sandbox: JsFiddle