variadicjs / variadic.js

A ES6 library of useful variadic functions.
https://variadicjs.github.io/
MIT License
7 stars 12 forks source link

Variadic factorial function #50

Closed jhowardjr closed 6 years ago

jhowardjr commented 6 years ago

Request help creating a factorial function that calculates the factorial value of each parameter in the parameter list.

devNoiseConsulting commented 6 years ago

Trying to figure out edge cases. 18! is 6402373705728000 which is the last factorial we can calculate before the code will exceed the Number.MIN_SAFE_INTEGER Number.MAX_SAFE_INTEGER. Do we limit all parameters to be 18 or less?

D1esel-Dev commented 6 years ago

i was thinking about this too.. and i'm sure you are meaning MAX_SAFE_INTEGER, maybe notation would be great for this like scientific, but it still would have to be calculated before converted, and just defeating the purpose, so maybe some algorithmic pattern can compute this. Will look into this.

RedQuark commented 6 years ago

If you limit yourself to integers with factorials less than Number.MAX_SAFE_INTEGER, then you don't need to calculate anything. Just put the factorials into a small lookup table.

jhowardjr commented 6 years ago

@redquark great observation!

devNoiseConsulting commented 6 years ago

Here's the code I have so far: https://github.com/devNoiseConsulting/variadic.js/blob/develop/lib/factorial.js

I'm doing the calculations, but also caching them so that we don't have to calculate every factorial and then using the highest value as the starting point for a new higher factorial.

In any case, I think we need to cap it at 18!. To overcome this we need to bring in a library that supports really big integers or we try to tackle that ourselves. Until either of those happen, I will write my error handling and test to work under that constraint.

jhowardjr commented 6 years ago

Nice memoization!

devNoiseConsulting commented 6 years ago

59 closed this issue.