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.
I know this is an ancient post...but I just recently got nailed during an interview on this one. So, here is my 'new & improved' answer:
Here is how it executes:
Here is the output of the above:
Here is my solution which addresses a test case where the input strings which are not anagrams, can be removed from the output. Hence the output contains only the anagram strings. Hope this is helpful.
I had this question in an interview. Given an array of words ['cat', 'dog', 'tac', 'god', 'act'], return an array with all the anagrams grouped together. Makes sure the anagrams are unique.
i have recently faced this in the coding interview, here is my solution.
output will be like
Here is my take:
where the output would be (the word, the match and the index of both):
To get the characters in the in alphabetical order, I used split("") ot get an array, called sort() and used join("") to get a string from the array.