JS Valid Anagram(leetcode 242)两个字符串包含的字符是否完全相同
Given two strings s and t , write a function to determine if t is an anagram of s.
Example 1:
Input: s = "anagram", t = "nagaram" Output: true
Example 2:
Input: s = "rat", t = "car" Output: false
Note:
You may assume the string contains only lowercase alphabets.
Follow up:
What if the inputs contain unicode characters? How would you adapt your solution to such case?
1 /** 2 * @param {string} s 3 * @param {string} t 4 * @return {boolean} 5 */ 6 7 var isAnagram = function(s, t) { 8 return (SortStr(s) === SortStr(t)); 9 10 }; 11 var SortStr = (str)=>{ 12 console.log(str.split('').sort().join('') ) 13 }