Published
Edited
Nov 27, 2020
Importers
Insert cell
md`# Branching using Map with default case`
Insert cell
class Branch extends Map {
get(key) {
if (!this.has(key)) return this.default;
return super.get(key);
}
constructor(defaultFunction, entries) {
super(entries);
this.default = defaultFunction;
}
}
Insert cell
m = new Branch(() => []);

Insert cell
m.get('whatever')
Insert cell
m.set('a','a')
Insert cell
m.get('a')
Insert cell
en = [
[1,"1"],
[2,"2"]
]
Insert cell
n = new Branch('def',en)
Insert cell
n.get(1)
Insert cell
n.get('anything')
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