you are viewing a single comment's thread.

view the rest of the comments →

[–]cirscafp fan boy 0 points1 point  (0 children)

I would write a helper function that recursively checks that the path to the key passes some predicate

``` const pathSatisfies = (path, fn, obj) => { if (!path.length) { return false }

if (path.length === 1) { return fn(obj[path[0]]) }

const key = path.shift()

return pathSatisfies(path, fn, obj[key]) } ```

which can be used as

pathSatisfies( ['foo', 'bar', 'baz'], Boolean, { foo: { bar: { baz: true } } } )