Created
May 21, 2021 10:58
-
-
Save Priyadarshanvijay/6a95c230873ed1f0706c82eff970dab6 to your computer and use it in GitHub Desktop.
Parsing Customer Parameter Groups From Nested 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
const getSpreadedArray = (inputObject) => { | |
if (!inputObject) return undefined; | |
const { groups } = inputObject; | |
if (groups.length === 0) return undefined; | |
const topLevelGroups = groups.map((group) => group && { params: group.params, name: group.name, input: group.input }).filter(Boolean); | |
const nestedGroups = groups.map((eachObject) => getSpreadedArray(eachObject)).filter(Boolean).flat(); | |
return [...nestedGroups, ...topLevelGroups]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment