{"ScriptPreparationCode":"var str = \u0027abcdefghi\u0027","TestCases":[{"Name":"recursive","Code":"const powerSetRec = ([head, ...tail]) =\u003E\r\n head == undefined\r\n ? [[]]\r\n : powerSetRec(tail).flatMap((subsets) =\u003E [subsets, subsets.concat(head)])\r\n\r\nconst stringPowerSet = (str) =\u003E\r\n powerSetRec([...str])\r\n .map((subset) =\u003E subset.sort().join(\u0027\u0027))\r\n .sort()\r\n .sort((a, b) =\u003E a.length - b.length)\r\nstringPowerSet(str)","IsDeferred":false},{"Name":"reduce","Code":"const powerSet = (arr) =\u003E {\r\n return arr.reduce(\r\n (subsetsSoFar, elem) =\u003E\r\n subsetsSoFar.concat(subsetsSoFar.map((subset) =\u003E subset.concat(elem))),\r\n [[]]\r\n )\r\n}\r\nconst stringPowerSet = (str) =\u003E\r\n powerSet([...str])\r\n .map((subset) =\u003E subset.sort().join(\u0027\u0027))\r\n .sort()\r\n .sort((a, b) =\u003E a.length - b.length)\r\nstringPowerSet(str)","IsDeferred":false},{"Name":"misc from random gist","Code":"var powerSet = function(str) {\r\n\r\n var set = [];\r\n var hash = {};\r\n if (!str) { str = \u0027\u0027; }\r\n str = str.split(\u0027\u0027).sort();\r\n\r\n // remove duplicates\r\n for (var i = 1; i \u003C str.length; i\u002B\u002B) {\r\n if (str[i - 1] === str[i]) {\r\n str.splice(i, 1);\r\n i--;\r\n }\r\n }\r\n\r\n // recursive through the sub sets\r\n var recurse = function(strSet) {\r\n var joined = strSet.join(\u0027\u0027);\r\n\r\n // check if we have visited this combo\r\n if (hash[joined]) { return; }\r\n hash[joined] = true;\r\n set.push(joined);\r\n\r\n // don\u0027t recurse to empty set - add it once at the end\r\n if (strSet.length === 1) { return; }\r\n\r\n // recurse all subsets\r\n for (var i = 0; i \u003C strSet.length; i\u002B\u002B) {\r\n var subSet = strSet.slice(0, i).concat(strSet.slice(i \u002B 1));\r\n recurse(subSet);\r\n }\r\n };\r\n recurse(str);\r\n set.push(\u0027\u0027); // the power set, by definition, includes the empty set\r\n\r\n return set;\r\n };\r\npowerSet(str)","IsDeferred":false}]}