{"ScriptPreparationCode":"var obj = {};\r\n\r\nfor (i = 1000; i \u003E 0; i--) {\r\n if (i%2 == 0) {\r\n \tobj[i] = \u0027String\u0027;\r\n } else {\r\n obj[i] = [ \u0027Array of String\u0027, \u0027Array of String\u0027 ];\r\n }\r\n}\r\n","TestCases":[{"Name":"forEach","Code":"function ClassList(collection={}) {\r\n const classNames = {};\r\n const keys = Object.keys(collection);\r\n\r\n keys.forEach((key) =\u003E {\r\n const innerCollection = collection[key];\r\n const collectionCheck = Object.prototype.toString.call(innerCollection);\r\n\r\n switch (collectionCheck) {\r\n case \u0027[object Object]\u0027: {\r\n const innerKeys = Object.keys(innerCollection);\r\n\r\n if (innerKeys.length === 0) {\r\n classNames[key] = \u0027\u0027;\r\n break;\r\n }\r\n\r\n let classList = [];\r\n innerKeys.forEach((innerKey) =\u003E {\r\n if (!innerCollection[innerKey] || !innerCollection[innerKey].length) {\r\n return;\r\n }\r\n\r\n const innerCollectionCheck = Object.prototype.toString.call(innerCollection[innerKey]);\r\n switch (innerCollectionCheck) {\r\n case \u0027[object Array]\u0027:\r\n classList.push(...innerCollection[innerKey]);\r\n break;\r\n\r\n case \u0027[object String]\u0027:\r\n classList.push(innerCollection[innerKey]);\r\n break;\r\n }\r\n });\r\n\r\n classNames[key] = classList.reduce((acc, cl) =\u003E (acc \u002B= cl \u002B \u0027 \u0027), \u0027\u0027);\r\n break;\r\n }\r\n\r\n case \u0027[object Array]\u0027:\r\n classNames[key] = innerCollection.reduce((acc, cl) =\u003E (acc \u002B= cl \u002B \u0027 \u0027), \u0027\u0027);\r\n break;\r\n\r\n case \u0027[object String]\u0027:\r\n classNames[key] = innerCollection;\r\n break;\r\n }\r\n });\r\n\r\n return classNames;\r\n}\r\n\r\nClassList( obj );","IsDeferred":false},{"Name":"Recursive 1","Code":"function recursor(obj, primaryKey, keys = [], classList = {}) {\r\n for (let k in obj) {\r\n const currentCol = obj[k];\r\n \r\n primaryKey = keys.indexOf(k) \u003E -1 ? k : primaryKey;\r\n classList[primaryKey] = classList[primaryKey] || \u0027\u0027;\r\n\r\n switch (Object.prototype.toString.call(currentCol)) {\r\n case \u0027[object Object]\u0027: {\r\n classList[primaryKey] = \u0027\u0027;\r\n if ( Object.keys(currentCol).length === 0 ) {\r\n break;\r\n }\r\n\r\n recursor(currentCol, primaryKey, keys, classList);\r\n break;\r\n }\r\n \r\n case \u0027[object Array]\u0027:\r\n classList[primaryKey] \u002B= currentCol.join(\u0027 \u0027) \u002B \u0027 \u0027;\r\n break;\r\n \r\n case \u0027[object String]\u0027:\r\n classList[primaryKey] \u002B= currentCol \u002B \u0027 \u0027;\r\n break;\r\n\r\n }\r\n }\r\n return classList;\r\n}\r\n\r\nfunction ClassList(collection = {}) {\r\n const keys = Object.keys(collection);\r\n return recursor(collection, false, keys);\r\n}\r\n\r\nClassList( obj );","IsDeferred":false},{"Name":"Recursive flatten","Code":"function ClassList(collection = {}) {\r\n const result = {};\r\n\r\n function flatten(node, str) {\r\n const nodeType = Object.prototype.toString.call(node);\r\n \r\n switch (nodeType) {\r\n case \u0027[object String]\u0027: {\r\n str \u002B= node \u002B \u0027 \u0027;\r\n break;\r\n }\r\n case \u0027[object Array]\u0027: {\r\n str \u002B= node.join(\u0027 \u0027) \u002B \u0027 \u0027;\r\n break;\r\n }\r\n case \u0027[object Object]\u0027: {\r\n for (const key in node) {\r\n str \u002B= flatten(node[key], \u0027\u0027);\r\n }\r\n break;\r\n }\r\n }\r\n \r\n return str;\r\n }\r\n\r\n for (const key in collection) {\r\n result[key] = flatten(collection[key], \u0027\u0027).trimEnd();\r\n }\r\n\r\n return result;\r\n}\r\n\r\nClassList(obj);","IsDeferred":false}]}