(easy) Write a function isAnagram which takes 2 parameters and returns true/false if those are anagrams or not. Whats Anagram? - A word, phrase, or name formed by rearranging the letters of another, such as spar, formed from rasp.

function isAnagram(str1, str2) {

}

Solution

function isAnagram(str1, str2) {
    // Check if both strings have the same length
    if (str1.length !== str2.length) {
      return false;
    }
    const a = str1.toUpperCase().split("").sort().join("");
    const b = str2.toUpperCase().split("").sort().join("");
    return a === b;
  }
  console.log("isana", isAnagram("spar", "rasp"));