Skip to content

Instantly share code, notes, and snippets.

@Priyadarshanvijay
Created May 21, 2021 10:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Priyadarshanvijay/6a95c230873ed1f0706c82eff970dab6 to your computer and use it in GitHub Desktop.
Save Priyadarshanvijay/6a95c230873ed1f0706c82eff970dab6 to your computer and use it in GitHub Desktop.
Parsing Customer Parameter Groups From Nested Object
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