Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Seating permutations - take a list of people and it gives you all possible seating arrangements
let seating = (people) => {
let result = [];
(function permutations (left, right) {
let current;
let before
let after;
if (right.length <= 1) {
result.push(left.concat(right));
return;
}
for (let i = 0; i < right.length; i++) {
current = right.slice(i, i + 1);
before = right.slice(0, i);
after = right.slice(i + 1, right.length);
permutations(left.concat(current), before.concat(after));
}
}([], people));
return result;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.