{"ScriptPreparationCode":"function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }\r\n\r\nfunction _nonIterableSpread() { throw new TypeError(\u0022Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\u0022); }\r\n\r\nfunction _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === \u0022string\u0022) return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === \u0022Object\u0022 \u0026\u0026 o.constructor) n = o.constructor.name; if (n === \u0022Map\u0022 || n === \u0022Set\u0022) return Array.from(o); if (n === \u0022Arguments\u0022 || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }\r\n\r\nfunction _iterableToArray(iter) { if (typeof Symbol !== \u0022undefined\u0022 \u0026\u0026 Symbol.iterator in Object(iter)) return Array.from(iter); }\r\n\r\nfunction _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }\r\n\r\nfunction _arrayLikeToArray(arr, len) { if (len == null || len \u003E arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i \u003C len; i\u002B\u002B) { arr2[i] = arr[i]; } return arr2; }\r\n\r\nfunction _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }\r\n\r\nvar words = [\u0027achenium\u0027, \u0027acheniums\u0027, \u0027acquitment\u0027, \u0027acquitments\u0027, \u0027actinometry\u0027, \u0027aeronomic\u0027, \u0027amercing\u0027, \u0027amnesic\u0027, \u0027androecium\u0027, \u0027androeciums\u0027, \u0027anemic\u0027, \u0027anoxemic\u0027, \u0027anthemic\u0027, \u0027anthropometric\u0027, \u0027archegonium\u0027, \u0027arcminute\u0027, \u0027arcminutes\u0027, \u0027axonometric\u0027, \u0027becalming\u0027, \u0027becharming\u0027, \u0027beclamoring\u0027, \u0027breadcrumbing\u0027, \u0027callistemon\u0027, \u0027callistemons\u0027, \u0027camerlingo\u0027, \u0027camerlingos\u0027, \u0027campesino\u0027, \u0027campesinos\u0027, \u0027camphine\u0027, \u0027camphines\u0027, \u0027campiness\u0027, \u0027carmine\u0027, \u0027carmines\u0027, \u0027caromelling\u0027, \u0027centigram\u0027, \u0027centigrams\u0027, \u0027centralism\u0027, \u0027centralisms\u0027, \u0027ceruloplasmin\u0027, \u0027ceruloplasmins\u0027, \u0027chairmen\u0027, \u0027chairwomen\u0027, \u0027chambering\u0027, \u0027chamberings\u0027, \u0027chamfering\u0027, \u0027championed\u0027, \u0027championess\u0027, \u0027charminger\u0027, \u0027charmingest\u0027, \u0027chazzenim\u0027, \u0027chimneyboard\u0027, \u0027chimneyboards\u0027, \u0027chloramine\u0027, \u0027chloramines\u0027, \u0027chlorpromazine\u0027, \u0027chlorpromazines\u0027, \u0027cinema\u0027, \u0027cinemas\u0027, \u0027clambering\u0027, \u0027clampering\u0027, \u0027cnemial\u0027, \u0027coalmine\u0027, \u0027coalminer\u0027, \u0027coalminers\u0027, \u0027coalmines\u0027, \u0027coinmate\u0027, \u0027coinmates\u0027, \u0027columniated\u0027, \u0027combinable\u0027, \u0027combinate\u0027, \u0027comedian\u0027, \u0027comedians\u0027, \u0027companied\u0027, \u0027companies\u0027, \u0027compassioned\u0027, \u0027compassionless\u0027, \u0027compearing\u0027, \u0027compellation\u0027, \u0027compellations\u0027, \u0027compendia\u0027, \u0027complained\u0027, \u0027complainer\u0027, \u0027complainers\u0027, \u0027complexation\u0027, \u0027complexations\u0027, \u0027complexional\u0027, \u0027compressional\u0027, \u0027confirmable\u0027, \u0027conservatism\u0027, \u0027conservatisms\u0027, \u0027conservatorium\u0027, \u0027conservatoriums\u0027, \u0027iceman\u0027, \u0027cinema\u0027];\r\n\r\nfunction findAnagrams(word, allWords) {\r\n var letters = word.split(\u0027\u0027);\r\n\r\n var charCount = function charCount(chars) {\r\n return chars.reduce(function (acc, char) {\r\n return _defineProperty({ ...acc\r\n }, char, acc[char] ? acc[char] \u002B 1 : 1);\r\n }, {});\r\n };\r\n\r\n var charCountObj = charCount(letters);\r\n console.log(charCountObj);\r\n return allWords.reduce(function (acc, w) {\r\n var charOfWordCount = charCount(w.split(\u0027\u0027));\r\n return word.length == w.length \u0026\u0026 word != w \u0026\u0026 Object.keys(charCountObj).every(function (key) {\r\n return charCountObj[key] == charOfWordCount[key];\r\n }) ? [].concat(_toConsumableArray(acc), [w]) : acc;\r\n }, []);\r\n};\r\n\r\nfunction countOccurrences(arr) {\r\n return arr.reduce(function (acc, str) {\r\n return _defineProperty({ ...acc\r\n }, str, acc[str] ? acc[str] \u002B 1 : 1);\r\n }, {});\r\n};\r\n\r\nfunction hasSameLetterCount(word1, word2) {\r\n var word1Count = countOccurrences(word1.split(\u0027\u0027));\r\n var word2Count = countOccurrences(word2.split(\u0027\u0027));\r\n return Object.keys(word1Count).length === Object.keys(word2Count).length \u0026\u0026 Object.keys(word1Count).every(function (letter) {\r\n return word1Count[letter] === word2Count[letter];\r\n });\r\n};\r\n\r\nfunction findAnagrams2(word, allWords) {\r\n return allWords.filter(function (entry) {\r\n return hasSameLetterCount(word, entry);\r\n }).filter(function (anagram) {\r\n return anagram !== word;\r\n });\r\n};\r\n\r\nvar sumForEach = 0,\r\n sumReduce = 0,\r\n sumMap = 0,\r\n sumFilter = 0,\r\n sumFor = 0;","TestCases":[{"Name":"filter","Code":"console.log(findAnagrams2(\u0027cinema\u0027, words));","IsDeferred":false},{"Name":"reduce","Code":"console.log(findAnagrams(\u0027cinema\u0027, words));","IsDeferred":false}]}