Public
Edited
Dec 31, 2022
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function editor(input) {
let str = input;
while (/12|13/g.test(str)) {
str = str.replace(/12/, "21");
str = str.replace(/31/, "23");
str = str.replace(/13/, "23");
}
return str;
}
Insert cell
input = "1".repeat(199) + "33"
Insert cell
result = editor(input)
Insert cell
sumOfNumbers = calculateSum(result)
Insert cell
calculateSum = str => str.split("")
.map(Number)
.reduce(function (a, b) {
return a + b;
}, 0)
Insert cell
Insert cell
Insert cell
animatedSumOfNumbers = calculateSum(
animatedResult.replace(/❶/g, "1").replace(/②/g, "2").replace(/③/g, "3")
)
Insert cell
animatedResult = {
replay;
return animatingEditor(stringToAnimate);
}
Insert cell
Insert cell
Insert cell
stringToAnimate = "❶".repeat(onesNumber) + "③③"
Insert cell
function* animatingEditor(input) {
let str = input;
while (/❶②|❶③/g.test(str)) {
str = str.replace(/❶②/, "②❶");
yield str;
str = str.replace(/③❶/, "②③");
yield str;
str = str.replace(/❶③/, "②③");
yield str;
}
}
Insert cell
Insert cell
Insert cell
state[counter]
Insert cell
Insert cell
Insert cell
currentSumOfNumbers = calculateSum(
state[counter].replace(/❶/g, "1").replace(/②/g, "2").replace(/③/g, "3")
)
Insert cell
start = "❶".repeat(onesNumberBySteps) + "③③"
Insert cell
Insert cell
state = editorSteps(start)
Insert cell
editorSteps = function (s) {
let history = [s];
let str = s;
while (/❶②|❶③/g.test(str)) {
str = str.replace(/❶②/, "②❶");
str = str.replace(/③❶/, "②③");
str = str.replace(/❶③/, "②③");
history.push(str);
}
return history;
}
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