export function mapVarcompDataToArray(data) { if (data.length < 3) return null; const mapResponse = {}; data.forEach((item) => { mapResponse[item.processType] = item; }); const tableConfig = { OptimusVarComp: { // Updated this line to match the case in your data name: "Optimus", fields: [ { name: "Record Count", key: "recordCount" }, { name: "Varcomp", key: "varComp" } ], dependency: [ { name: "DASHIDM", key: "DashIDMVarcomp" }, { name: "Disbursement", key: "MercuryVarcomp" } ] } }; const table = {}; for (const source in tableConfig) { for (let index = 0; index < tableConfig[source]["dependency"].length; index++) { const target = tableConfig[source]["dependency"][index]; const balancingFields = tableConfig[source]["fields"]; const test = []; balancingFields.forEach((field) => { const test2 = {}; if (mapResponse[source] && mapResponse[source][field["key"]]) { test2[tableConfig[source]["name"]] = mapResponse[source][field["key"]]; } if (mapResponse[target["key"]] && mapResponse[target["key"]][field["key"]]) { test2[target["name"]] = mapResponse[target["key"]][field["key"]]; } test2["columnName"] = field["name"]; if (Object.values(test2).length > 1) test.push(test2); }); table[target["name"]] = test; } } return table; }