Skip to content

Instantly share code, notes, and snippets.

@alexlenail
Created October 29, 2018 02:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexlenail/d5067822731d21e026efc64c5c0d2a73 to your computer and use it in GitHub Desktop.
Save alexlenail/d5067822731d21e026efc64c5c0d2a73 to your computer and use it in GitHub Desktop.
var DefaultDict = (initValue) => new Proxy({}, {
get: (target, name) => name in target ? target[name] :
(target[name] = (typeof initValue === 'function' ? initValue() : initValue))
});
statistics = DefaultDict(() => DefaultDict(() => DefaultDict(0)));
// Thanks @jonathanzong!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment