var groupAnagrams = function(strs) {
var m = new Map();
var list = strs.map((e,index)=>{
return [e.split('').sort().join(),index]
}).forEach(e=>{
if(m.has(e[0]))
m.get(e[0]).push(strs[e[1]]);
else
m.set(e[0],[strs[e[1]]]);
});
return list;
};
console.log(
groupAnagrams(
["eat", "tea", "tan", "ate", "nat", "bat"]
)
)
<p>jj</p>