Anagram checker in javascript

a simple anagram checker using javascript

function checkAnagram(a, b) {
   let text1 = a.length;
   let text2 = b.length;
   if(text1 !== text2){
      console.log('Invalid Input, Character Length not matching');
      return
   }
   let str1 = a.split('').sort().join('');
   let str2 = b.split('').sort().join('');
   if(str1 === str2){
      console.log("True");
   } else { 
      console.log("False");
   }
}
checkAnagram("facebook","boacefok")

 

 

Leave a Reply 0

Your email address will not be published. Required fields are marked *