var groupAnagrams = function (strs) {
const anagramPair = []
for (let i = 0; i < strs.length; i++) {
for (let j = i + 1; j < strs.length; j++) {
if (strs[i].split('').sort().join('') === strs[j].split('').sort().join('')) {
if (anagramPair.some(str => str === strs[i])) {
const originalPairIndex = anagramPair.indexOf(strs[i])
anagramPair[originalPairIndex].push(strs[j])
} else {
anagramPair.push([strs[i], strs[j]])
}
} else {
anagramPair.push([strs[j]])
}
}
}
return anagramPair
};
dmFyIGdyb3VwQW5hZ3JhbXMgPSBmdW5jdGlvbiAoc3RycykgewoKICAgIGNvbnN0IGFuYWdyYW1QYWlyID0gW10KCiAgICBmb3IgKGxldCBpID0gMDsgaSA8IHN0cnMubGVuZ3RoOyBpKyspIHsKICAgICAgICBmb3IgKGxldCBqID0gaSArIDE7IGogPCBzdHJzLmxlbmd0aDsgaisrKSB7CiAgICAgICAgICAgIGlmIChzdHJzW2ldLnNwbGl0KCcnKS5zb3J0KCkuam9pbignJykgPT09IHN0cnNbal0uc3BsaXQoJycpLnNvcnQoKS5qb2luKCcnKSkgewogICAgICAgICAgICAgICAgaWYgKGFuYWdyYW1QYWlyLnNvbWUoc3RyID0+IHN0ciA9PT0gc3Ryc1tpXSkpIHsKICAgICAgICAgICAgICAgICAgICBjb25zdCBvcmlnaW5hbFBhaXJJbmRleCA9IGFuYWdyYW1QYWlyLmluZGV4T2Yoc3Ryc1tpXSkKICAgICAgICAgICAgICAgICAgICBhbmFncmFtUGFpcltvcmlnaW5hbFBhaXJJbmRleF0ucHVzaChzdHJzW2pdKQogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICBhbmFncmFtUGFpci5wdXNoKFtzdHJzW2ldLCBzdHJzW2pdXSkKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIGFuYWdyYW1QYWlyLnB1c2goW3N0cnNbal1dKQogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQogICAgcmV0dXJuIGFuYWdyYW1QYWlyCn07