Thanks to this comment on Reddit I got the info about the name
Last active
December 8, 2022 15:15
-
-
Save Rudxain/370f6d6e8fb7571f120c53d59c375ac5 to your computer and use it in GitHub Desktop.
Access any value within a tree, at any depth. Ported from Clojure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
/** | |
@param {unknown} struct | |
@param {Iterable<unknown>} keys | |
*/ | |
const get_in = (struct, keys) => { | |
for (const k of keys) | |
struct = | |
struct instanceof Map || | |
struct instanceof WeakMap | |
? struct.get(k) | |
: struct[k] | |
return struct | |
} | |
//LICENSE: https://unlicense.org |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment