So here is my code: Egg Drop Calculator - Replit
It may look like a lot, but the part I am struggling on is line 38
Now if you read through the comments, you can see on line 19 I make a function that generates a random combination of the string input (now an array).
Note this is just a snippet of a bigger function, but I included all the variables so it will still work. The output should be a list of every combination of 123 (no repeats).
123, 132, 213, 231, 312, 321
On 35, you can see I have a loop to call the randomCombo()
function with the setTimeout()
function with a delay of 1 millisecond(s). This makes a random combination of my string
(really an array).
On line 42 I go through the combinations and if this new combo matches a combination in my list of combinations, I then give it a length of 0 (empty array).
On line 50 I check the new combination and if I set it to an empty array in the previous loop I then ignore it and do now add it. otherwise, I do add it to my list of combinations.
On line 57 I reset my variable and then do this all over again until I get my desired combinations per my fact
(factorial) variable.
Now when you click to run it, it takes forever to run and it should only take < 60 milliseconds. If it is anything over a second, something is off. Then i get this thing:
Here is a short snippet of it:
<— JS stacktrace —>
==== JS stack trace =========================================
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memoryHopefully, this made sense.
What does this mean? Why am I getting this?