InternalError: too much recursion

URL of experiment:

Description of the problem: I use builder view and have a custom code in it that shuffle the list of numbers that need to be presented to participants. I’ve recently changed my code in order to counterbalance trials in my experiment. Here is the code:

def shuffle_list(List):
    for ii in List:
        d = difFinder(ii)
        if(d == 1):
            counta += 1
        elif(d == 2):
            countb += 1
        elif(d == 3):
            countc += 1
    if(counta == countb and counta == countc):
        return List
        return shuffle_list(List)
def difFinder(i):
    if i[0] != i[1] and i[0] != i[2]:
        return 1;
    if i[1] != i[0] and i[1] != i[2]:
        return 2;
    if i[2] != i[0] and i[2] != i[1]:
        return 3;

While running locally it’s ok but online, it gives this error:
InternalError: too much recursion
How can I fix the code to prevent this error?
Thank you for your help.

I recently learned that for def to work in an auto translate code component online, it needs to go in a Before Experiment tab.

Hi @wakecarter . Thanks for your suggestion. I did what you just said but I get this error:
TypeError: shuffle is not a function
I didn’t have this problem when my codes were in begin experiment tab. I just moved whatever was in “begin experiment” to “before experiment”.

And moving my codes to before experiment didn’t have any effect on this error of too much recursion.
@sotiri Do you happen to know what should I do with this error? How can I fix it?

And I should mention that the error while running the experiment in Chrome is like this:

  • RangeError: Maximum call stack size exceeded
    Which I searched and found out that these are kind of the same errors.
    In my experiment, I really need to counterbalance the number of times the first list differs from the other two, the second list differs from the other two, and the third list differs from the other two.
    If you think I can achieve the same goal with another programming for this or by including a function or something in my jscode it would help me a lot.

Have a look at my crib sheet for how to define shuffle in code_JS

Hi @zhaleh, were you able to sort this one out? I get a 404 when I visit the GitLab repo, x