This commit is contained in:
Anish Tiwari 2024-07-17 10:36:40 +09:00 committed by GitHub
commit 7377c908d9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -0,0 +1,21 @@
// TO CHECK IF TWO STRINGS ARE ANAGRAM OR NOT
function anagram(word1, word2) {
let sorted1 = word1.split('').sort().join(''); //SORTING WORD1
let sorted2 = word2.split('').sort().join(''); //SORTING WORD2
//COMPARING LENGTH AND CHECKING ===
if (sorted1.length === sorted2.length && sorted1 === sorted2) {
return true;
}
else{
return false;
}
}
if(anagram('binary', 'brainy')){
alert('AN ANAGRAM');
}
else{
alert('NOT AN ANAGRAM');
}