Published
Edited
Dec 10, 2018
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function part1 (s) {
let stack = [];
for (const char of s) {
if (stack.length && char === toggleCase[stack.slice(-1)]) {
stack.pop();
} else {
stack.push(char);
}
}
return stack;
}
Insert cell
reducedPolymer = part1(input)
Insert cell
reducedPolymer.length
Insert cell
Insert cell
function part2 (s) {
let lengths = [];
for (const char of alphabet) {
const sWithoutChar = s.filter(c => c.toLowerCase() !== char);
lengths.push(part1(sWithoutChar).length);
}
return Math.min(...lengths);
}
Insert cell
part2(reducedPolymer)
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