Skip to content

Instantly share code, notes, and snippets.

View Priyadarshanvijay's full-sized avatar
🏠
Working from home

Priyadarshan Vijay Priyadarshanvijay

🏠
Working from home
View GitHub Profile
@Priyadarshanvijay
Priyadarshanvijay / parseCustomerParamsGroups.js
Created May 21, 2021 10:58
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];
}