Public
Edited
Jan 3, 2024
Insert cell
Insert cell
pairUp(Array.from({ length: 8 }).map((_, i) => i))
Insert cell
pairUp(
Array.from({ length: 8 }).map((_, i) => i),
true
)
Insert cell
pairUp = (input, loop = false) => {
const result = [];
for (let i = 0; i < input.length; i++) {
if (!loop && i === input.length - 1) {
continue;
}
result[i] =
i === input.length - 1 ? [input[i], input[0]] : [input[i], input[i + 1]];
}
return result;
}
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