Easy to Understand Set & Map (TypeScript)
Intuition\nFirst removes all the duplicate characters from each word. Then, it compares each word to every other word in the array. If the two words have the sa
# Intuition\nFirst removes all the duplicate characters from each word. Then, it compares each word to every other word in the array. If the two words have the same set of characters, then they are considered to be similar pairs.\n\n# Approach\nFirst, collect distinct characters from each word using a \'Set\'. Then, consolidate these characters into a sorted string and record it in the \'arr\' map. After processing all words, calculate the total pairs by summing up the counts of identical words.\n\n# Complexity\n- Time complexity: $$O(n*m)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n+m)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nfunction similarPairs(words: string[]): number {\n     let arr = new Map<string,number>();\n     let sum = 0;\n     for(let word of words){\n         let str: { [key: string]: number } = {};\n          for(let i=0;i<word.length;i++){\n                str[word[i]]++;\n          }\n          let tmp:string="";\n          for(let key in str){\n               tmp+=key;\n          }\n          tmp = tmp.split(\'\').sort().join(\'\');\n          console.log(tmp);\n          if(arr.has(tmp)){\n                arr.set(tmp,arr.get(tmp)+1);\n          }\n          else{\n               arr.set(tmp,1);\n          }\n     }\n\n     for(let val of arr.values()){\n          if(val>1){\n                val--;\n                sum+= val*(val+1)/2 ;\n          }\n     }\n     return sum;\n\n};\n```
['TypeScript', 'JavaScript']