{"ScriptPreparationCode":"var inputs = [{\r\n id: 1,\r\n type: \u0027product\u0027,\r\n quantity: 5\r\n },\r\n {\r\n id: 2,\r\n type: \u0027product\u0027,\r\n quantity: 2\r\n },\r\n {\r\n id: 3,\r\n type: \u0027bundle\u0027,\r\n quantity: 1,\r\n items: [{\r\n id: 4,\r\n type: \u0027product\u0027,\r\n quantity: 1\r\n },\r\n {\r\n id: 5,\r\n type: \u0027product\u0027,\r\n quantity: 1\r\n },\r\n {\r\n id: 6,\r\n type: \u0027product\u0027,\r\n quantity: 2\r\n },\r\n {\r\n id: 8,\r\n type: \u0027unknown\u0027,\r\n quantity: 2\r\n }\r\n ]\r\n },\r\n {\r\n id: 7,\r\n type: \u0027product\u0027,\r\n quantity: 1\r\n },\r\n {\r\n id: 8,\r\n type: \u0027unknown\u0027,\r\n quantity: 1\r\n }\r\n]\r\n\r\nfunction extractBundleItems(bundle) {\r\n return bundle.items.map(item =\u003E {\r\n return {\r\n item_id: item.id,\r\n item_type: item.type,\r\n quantity: item.quantity\r\n }\r\n })\r\n}","TestCases":[{"Name":"Map \u002B filter \u002B flat","Code":"inputs.map((item) =\u003E {\r\n if (item.type === \u0027product\u0027) {\r\n return {\r\n item_id: item.id,\r\n item_type: item.type,\r\n quantity: item.quantity,\r\n }\r\n }\r\n \r\n if (item.type === \u0027bundle\u0027) {\r\n return extractBundleItems(item)\r\n }\r\n \r\n return null\r\n}).filter(Boolean).flat()","IsDeferred":false},{"Name":"Reduce","Code":"inputs.reduce((results, item) =\u003E {\r\n if (item.type === \u0027product\u0027) {\r\n results.push({\r\n item_id: item.id,\r\n item_type: item.type,\r\n quantity: item.quantity,\r\n })\r\n }\r\n \r\n if (item.type === \u0027bundle\u0027) {\r\n results.push(...extractBundleItems(item))\r\n }\r\n \r\n return results\r\n}, [],)","IsDeferred":false}]}