I'm attempting to find all anagrams in an array of words:
arr = ['cab','bac','tru']
The expected result should be:
{abc: ['cab','bac']}
Here's the code I've tried so far:
var words = ['cab', 'bac', 'mihir']
let result = {}
words.forEach(word => {
var a = word.split("").sort().join("");
result[word] = a
})
console.log(result)
Is there a way to loop through the values to access keys with identical values?