Public
Edited
Dec 18, 2022
Insert cell
Insert cell
Insert cell
processInstructions(instructions)
Insert cell
function processInstructions(instructions) {
const atomic = _.flatMap(instructions, ({ cmd, value }) => {
if (cmd === "noop") {
return [{ cmd }];
}

if (cmd === "addx") {
return [
{ cmd, value: 0 },
{ cmd, value }
];
}
});

const results = atomic.map((item, j, list) => {
cycle: j, x: j > 0? list[j -1] +item.value
})
}
Insert cell
instructions = parseInput(sampleInput)
Insert cell
function parseInput(input) {
return input
.trim()
.split("\n")
.map((line) => line.split(" "))
.map(([cmd, value]) => (cmd === "noop" ? { cmd } : { cmd, value: +value }));
}
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