{"ScriptPreparationCode":"var input = { foo: \u0027lorem\u0027, bar: \u0027ipsum\u0027, baz: null }\r\nvar reduce = (itemsArray, callback, seed) =\u003E {\r\n let accumulator = seed;\r\n for (let i = 0; i \u003C itemsArray.length; i \u002B= 1) {\r\n accumulator = callback(accumulator, itemsArray[i], i);\r\n }\r\n return accumulator;\r\n};","TestCases":[{"Name":"Reduce","Code":"const keys = [\u0027foo\u0027, \u0027bar\u0027, \u0027baz\u0027];\r\nconst setProperty = (acc, key, value) =\u003E value ? (acc[key] = value) \u0026\u0026 acc : acc;\r\n\r\nconst result = keys.reduce((acc, key) =\u003E setProperty(acc, key, input[key]), {});\r\n\r\nObject.entries(result).map(\r\n ([key, value]) =\u003E \u0060data-analytics-view-custom-analytics-${key}=\u0022${value}\u0022\u0060,\r\n)","IsDeferred":false},{"Name":"Looping","Code":"const keys = [\u0027foo\u0027, \u0027bar\u0027, \u0027baz\u0027];\r\nconst setProperty = (acc, key, value) =\u003E value ? (acc[key] = value) \u0026\u0026 acc : acc;\r\n\r\nconst result = reduce(\r\n keys,\r\n (acc, key) =\u003E setProperty(acc, key, input[key]),\r\n {}\r\n);\r\n\r\nObject.entries(result).map(\r\n ([key, value]) =\u003E \u0060data-analytics-view-custom-analytics-${key}=\u0022${value}\u0022\u0060,\r\n)","IsDeferred":false},{"Name":"Ifs","Code":"const { foo, bar, baz } = input;\r\n\r\nconst result = {};\r\n\r\nif (foo) {\r\n result.foo = foo;\r\n}\r\n\r\nif (bar) {\r\n result.bar = bar;\r\n}\r\n\r\nif (baz) {\r\n result.baz = baz;\r\n}\r\n\r\nObject.entries(result).map(\r\n ([key, value]) =\u003E \u0060data-analytics-view-custom-analytics-${key}=\u0022${value}\u0022\u0060,\r\n)","IsDeferred":false},{"Name":"Destructuring","Code":"const { foo, bar, baz } = input;\r\nconst result = { foo, bar, baz };\r\n\r\nObject.entries(result).map(\r\n ([key, value]) =\u003E value ? \u0060data-analytics-view-custom-analytics-${key}=\u0022${value}\u0022\u0060 : \u0027\u0027,\r\n)","IsDeferred":false}]}