I\'m trying to write a function that does the following:
const rotations = ([l, ...ls], right=[]) => l ? [[l, ...ls, ...right], ...rotations(ls, [...right, l])] : [] const permutations = ([x, ...xs]) => x ? permutations(xs).flatMap((p) => rotations([x, ...p])) : [[]] console.log(permutations("cat"))