There is a code to search for anagrams, get an array of all anagrams, sort it and take an anagram index from an array that matches the source word. But there is a problem, for long words the code is very slow, maybe someone has already encountered such a problem? I will be glad to advice and help!
function listPosition(word) { var arr = [word]; var anagrams = {}; arr.forEach(function(str) { var recurse = function(ana, str) { if (str === '') anagrams[ana] = 1; for (var i = 0; i < str.length; i++) recurse(ana + str[i], str.slice(0, i) + str.slice(i + 1)); }; recurse('', str); }); var result = Object.keys(anagrams); return result.sort().indexOf(word) + 1; } console.log(listPosition('BOOKKEEPER'));
1, 2), your actions (a + a + b), the output you received (4) and the output you need (3). We can correct (a + b). - user207618