Last active
December 3, 2019 13:47
-
-
Save DarwinniwraD/ad064d3858a403e257868dc15677903a to your computer and use it in GitHub Desktop.
array of objects to tree
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
export default const getUnflatten = (arr, idFieldName, parentFieldName) => (arr, parentid) => arr.reduce((all, item) => item[parentFieldName] === parentid ? all.concat({...item, children: getUnflatten(arr, item[idFieldName])}): all, [] ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment