Created
December 31, 2020 00:32
-
-
Save redgeoff/2d3303eb3ab3e5a6443e1b30813d331d to your computer and use it in GitHub Desktop.
eachDeep - Recursively traverse object
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
import each from 'lodash/each'; | |
const eachDeepInner = (collection, iteratee, key) => { | |
if (key !== undefined) { | |
iteratee(collection, key) | |
} | |
if (collection && typeof collection === 'object') { | |
each(collection, (value, key) => { | |
eachDeepInner(value, iteratee, key); | |
}) | |
} | |
} | |
const eachDeep = (collection, iteratee) => { | |
eachDeepInner(collection, iteratee); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment