Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

detect two strings are anagram of each other in JavaScript

function checkAnagram(str1, str2)
{
    let s1 = str1.trim().split(" ").join("").split("").sort();
    let s2 = str2.trim().split(" ").join("").split("").sort();
    if(s1.length!=s2.length) console.log("False");
    else{
        result = true;
        for(let i=0; i<s1.length; i++){
            if(s1[i]!=s2[i]){
                result = false;
                break;
            }
        }
        if(result) console.log("True");
        else console.log("False");
    }
}
 
PREVIOUS NEXT
Tagged: #detect #strings #anagram #JavaScript
ADD COMMENT
Topic
Name
9+7 =