function getPermutations (arr, numberToSelect) {
const permutations = [];
if (numberToSelect === 1) return arr.map((el) => [el]);
for (const [index, fixedVal] of Object.entries(arr)) {
const rest = [...arr.slice(0, +index), ...arr.slice(+index + 1)];
const childPermutations = getPermutations(rest, numberToSelect - 1);
const attached = childPermutations.map((el) => [fixedVal, ...el]);
permutations.push(...attached);
}
return permutations;
};