
js
/**
* @param {string[]} strs
* @return {string[][]}
*/
var groupAnagrams = function (strs) {
// for of 用在可迭代对象上
const m = new Map()
// for ... of 用来遍历可迭代对象
for (const s of strs) {
// s.split 将字符串转变成数组
const sorted = s.split('').sort().join('')
if (!m.has(sorted)) {
m.set(sorted, [])
}
m.get(sorted).push(s)
}
// m.values() 返回可迭代对象, Array.from 从可迭代对象构建数组
return Array.from(m.values())
}