How to avoid the browser to freeze with very long function

I’m trying to make a program to create a duty shifts table for a medical department.
To do that, i create all the possibile combination of doctor–>shift of all the days, then I have to create all possible combinations to select which are the bests.
This is an array of arrays combinations, which it can be so long, and browser stuck.
I read I can use setTimeout in my for loop, but I didn’t understand how.

I have this code (previously I used recursion but I read it’s better not to):

function newCombos (list, miglioriComb=[], punteggioX=[], current = []){
for (let a in list[0]){
for (let b in list[1]){
for (let c in list[2]){
for (let d in list[3]){
for (let e in list [4]){
current =[list[0][a],list[1][b],list[2][c],list[3][d],list[4][e]]; //create combinations
let tempODS=creaODS(current);//here I evaluate the combination
        let tempPunteggio=calcolaPenalty(tempODS);
//now I insert in an array the best combinations and in another array the best score(less is better)
        if (punteggioX.length===0) {punteggioX.push(tempPunteggio); miglioriComb.push(current); }
            else for (jj=0;jj<punteggioX.length; jj++){
            if (tempPunteggio<punteggioX[jj]) {
                    punteggioX.splice(jj, 0, tempPunteggio);
                miglioriComb.splice(jj, 0, current);
                if (punteggioX.length>lunghezzaMax){ punteggioX.splice(-1); miglioriComb.splice(-1);} 
                    break;}
        else if (punteggioX.length<lunghezzaMax) {punteggioX.push(tempPunteggio); miglioriComb.push(current);}}
      
}}}}}
return {miglioriComb, punteggioX};}

list is something like this (but with much much more values):

[
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
];

How can I put in this code a setTimeout to avoid the browser to stuck?

Is there a way to return in console.log or in the HTML at which point is the function (like a percentage)?.

Is better to use a webworker?

Thanks a lot