Answers for "js defaultdict"

1

js defaultdict

function makeDefaultDict(factory) {
    return new Proxy({}, {
        get(target, name) {
            if (!(name in target)) {
                target[name] = factory()
            }
            return target[name]
        }
    })
}
Posted by: Guest on May-28-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language