const isAnagram = (str1, str2) => {
    str1 = str1.replace(/[^a-z0-9]/gi, '').toLowerCase();
  str2 = str2.replace(/[^a-z0-9]/gi, '').toLowerCase();

  // Check if lengths match after cleaning strings
  if (str1.length !== str2.length) {
    return false;
  }
  const obj = {}
  let flag = true
  const length = Math.max(str1.length, str2.length)
  for(i=0; i<length; i++){
      
      if(i<str2.length ){
          obj[str2[i]] = (obj[str2[i]] || 0) + 1
      }
      if(i<str1.length){
          obj[str1[i]] = (obj[str1[i]] || 0) + 1
      }
  }
console.log(obj)
   for(const [key,value] of Object.entries(obj)) {
       console.log(!(value%2 ===0), value, key)
       if(!(value%2 === 0)){
           return false
       }
   }
    
   return flag
    
 
    
}

console.log(isAnagram("New York Times", "monkeys wr-ite"))

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: