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
Prev Previous commit
Next Next commit
corrected the code and added indentation
AnishTiwari authored Sep 18, 2018

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 672e2864a8a4bb64f979f401c4462b02bd287837
23 changes: 10 additions & 13 deletions src/algorithms/string/anagram.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
// 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
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;
}
//COMPARING LENGTH AND CHECKING ===
if (sorted1.length == sorted2.length && sorted1 === sorted2) {
return true;
}
else{
return false;
}
}

if(anagram(word1,word2)){
if(anagram("binary", "brainy")){
alert("AN ANAGRAM");
}
else{
alert("NOT AN ANAGRAM");
}
anagram("sasdas", "sdasda");