I\'m trying to write a function that does the following:
Functional answer using flatMap:
const getPermutationsFor = (arr, permutation = []) => arr.length === 0 ? [permutation] : arr.flatMap((item, i, arr) => getPermutationsFor( arr.filter((_,j) => j !== i), [...permutation, item] ) );