{"ScriptPreparationCode":"var arr = [\u0027cook\u0027, \u0027eat\u0027, \u0027ate\u0027, \u0027cat\u0027, \u0027cat\u0027, \u0027save\u0027, \u0027vase\u0027, \u0027state\u0027, \u0027taste\u0027];","TestCases":[{"Name":"looping to compare properties","Code":"const objStr = {};\r\n\r\nfor (const str of arr) {\r\n const strCount = {};\r\n for (const letter of str) {\r\n strCount[letter] = (strCount[letter] || 0) \u002B 1;\r\n }\r\n objStr[str] = strCount;\r\n}\r\n\r\nconst result = [];\r\n\r\nfor (const str of arr) {\r\n let indexed = null;\r\n\r\n for (const grouped of result) {\r\n const [indexedStr] = grouped;\r\n if (str.length !== indexedStr.length) {\r\n continue;\r\n }\r\n\r\n const strCount = objStr[str];\r\n const indexedCount = objStr[indexedStr];\r\n let isAnagram = true;\r\n for (const letter in indexedCount) {\r\n if (strCount[letter] !== indexedCount[letter]) {\r\n isAnagram = false;\r\n break;\r\n }\r\n }\r\n\r\n if (isAnagram) {\r\n indexed = grouped;\r\n break;\r\n }\r\n }\r\n\r\n if (!indexed) {\r\n result.push([str]);\r\n } else {\r\n indexed.push(str);\r\n }\r\n}","IsDeferred":false},{"Name":"less loop but with char code and json stringify","Code":"const objStr = {};\r\n\r\nfor (const str of arr) {\r\n const strCount = {};\r\n for (const letter of str) {\r\n const charCode = letter.charCodeAt(0);\r\n strCount[charCode] = (strCount[charCode] || 0) \u002B 1;\r\n }\r\n const strCodes = JSON.stringify(strCount);\r\n if (objStr[strCodes]) {\r\n objStr[strCodes].push(str);\r\n } else {\r\n objStr[strCodes] = [str];\r\n }\r\n}\r\n\r\nconst hasil = Object.values(objStr);","IsDeferred":false}]}