Understanding heap algorithm

Tell us what’s happening:

This problem maybe easier for others , but I’m not getting this solution.
Solution I posted here is just the solution given in get Hint section.
Will be good if someone explain this algorithm to me(to find the permutations)

Your code so far

function permAlone(str){
 var regex = /(.)\1/;

 var arr = str.split("");
 var permutations = [];
 var tmp;

 if (str.match(regex) !== null && str.match(regex)[0] === str) return 0;
 function generate(int) {
   if (int === 1) {
   } else {
     for (var i = 0; i != int; ++i) {
       generate(int - 1);
       tmp = int%2?0:i;
       [arr[tmp], arr[int-1]] = [arr[int-1], arr[tmp]];

 // Filter the array of repeated permutations.
return permutations.filter( string=> !string.match(regex)).length;

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36.

Challenge: No Repeats Please

Link to the challenge: