Last active
December 31, 2020 00:31
-
-
Save redgeoff/868196d18356e5b8d4c6c341f7f4a40b to your computer and use it in GitHub Desktop.
eachLeaf - Recursively process each leaf in JavaScript 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 eachLeafInner = (collection, iteratee, key) => { | |
if (collection && typeof collection === 'object') { | |
each(collection, (value, key) => { | |
eachLeafInner(value, iteratee, key); | |
}) | |
} else if (key !== undefined) { | |
iteratee(collection, key) | |
} | |
} | |
const eachLeaf = (collection, iteratee) => { | |
eachLeafInner(collection, iteratee); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment