js defaultdict code example
Example: js defaultdict
function makeDefaultDict(factory) {
return new Proxy({}, {
get(target, name) {
if (!(name in target)) {
target[name] = factory()
}
return target[name]
}
})
}