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