Public
Edited
Dec 19, 2022
Insert cell
Insert cell
Insert cell
names2 = ({
// Fred: { exclude: "Wilma" },
// Barney: { exclude: "Betty" },
// Wilma: { exclude: "Fred" },
// Betty: { exclude: "Barney" },
George: null,
Jane: null,
// Judy: { require: "Elroy" },
Elroy: null
})
Insert cell
processConfig(names2, 3)
Insert cell
processConfig = (config, seed) => {
const shuffler = d3.shuffler(createRandomizer(seed));
const people = Object.entries(config);
const requires = people
.map(([from, config]) => ({ from, to: config?.require }))
.filter((d) => !!d.to);
const resolved = requires.map(({ to, from }) => [to, from]).flat();
const names = people
.map(([name]) => name)
.filter((name) => !resolved.includes(name));

const rest = names
.map((from, i) => removeAtIndex(names, i).map((to) => ({ from, to })))
.map((group, i) => ({
group,
config: config[names[i]]
}))
.map(({ group, config }) =>
group
.filter((d) => (!!config?.require ? d.to === config.require : true))
.filter((d) => !forceArray(config?.exclude).includes(d.to))
)
.reduce((results, group) => {
const used = results.map((d) => d.to);
console.log({ results, used, group });
const options = group.filter((d) => !used.includes(d.to));
const result = shuffler(options)[0];
return [...results, result];
}, []);

return [...requires, ...rest];
}
Insert cell
Insert cell
Insert cell
exchange = d3.zip(names, noSelfExchangeShuffle(names, "frog"))
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
createRandomizer = (seed) =>
!!seed ? d3.randomUniform.source(seedrandom(seed))(0, 1) : Math.random
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more