Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create anagram.js #182

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Create anagram.js
two strings are anagram or not
AnishTiwari authored Aug 27, 2018

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 04b5a93fdfafbfde7d092164af784ebe57c675be
24 changes: 24 additions & 0 deletions src/algorithms/string/anagram.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// TO CHECK IF TWO STRINGS ARE ANAGRAM OR NOT

function anagram(word1, word2){
var sorted1 = word1.split("").sort().join("");//SORTING WORD1
var 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(word1,word2)){
alert("AN ANAGRAM");
}
else{
alert("NOT AN ANAGRAM");
}
anagram("sasdas", "sdasda");