Public
Edited
Dec 1, 2023
Insert cell
Insert cell
Insert cell
function mode(xs) {
const fTable = new Map();
xs.forEach((x) => AOC.addToFreqTable(fTable, x));
return [...fTable].sort(([_, f1], [__, f2]) => f2 - f1)[0][0];
}
Insert cell
Insert cell
function part1(input) {
return AOC.transposeArray(input.split("\n").map((row) => [...row]))
.map(mode)
.join("");
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function leastCommon(xs) {
const fTable = new Map();
xs.forEach((x) => AOC.addToFreqTable(fTable, x));
return [...fTable].sort(([_, f1], [__, f2]) => f1 - f2)[0][0];
}
Insert cell
function part2(input) {
return AOC.transposeArray(input.split("\n").map((row) => [...row]))
.map(leastCommon)
.join("");
}
Insert cell
Insert cell
Insert cell
Insert cell
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