From 672e2864a8a4bb64f979f401c4462b02bd287837 Mon Sep 17 00:00:00 2001 From: AnishTiwari Date: Tue, 18 Sep 2018 12:59:07 +0530 Subject: [PATCH] corrected the code and added indentation --- src/algorithms/string/anagram.js | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/algorithms/string/anagram.js b/src/algorithms/string/anagram.js index 8455c16d..b96c9765 100644 --- a/src/algorithms/string/anagram.js +++ b/src/algorithms/string/anagram.js @@ -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");