I am supposed to write a program in JavaScript to find all the anagrams within a series of words provided. e.g.: "monk, konm, nkom, bbc, cbb, dell, ledl, llde" The output should be categorised into rows: 1. monk konm, nkom; 2. bbc cbb; 3. dell ledl, llde;
I already sorted them into alphabetical order i.e.: "kmno kmno bbc bbc dell dell" and put them into an array.
However I am stuck in comparing and finding the matching anagram within the array.
Any help will be greatly appreciated.
Maybe this?
It'd return something like
It's a simple version of what you wanted and certainly it could be improved avoiding duplicates for example.
My two cents.
This approach uses XOR on each character in both words. If the result is 0, then you have an anagram. This solution assumes case sensitivity.
Best and simple way to solve is using for loops and traversing it to each string and then store their result in object.
Here is the solution :-
Probably not the most efficient way, but a clear way around using es6