I’m guessing that some “array” needs to be empty before it’s generated (again). It’s a long function (nicely structured!) to check it out, so it’s hard for me to point out which line would be that
In cases like that, I often use console.log()
to see what and where something is generated.
Cheers, Marko