Created
April 14, 2016 22:10
-
-
Save bytorbrynden/ea8c13abe2abcbf4ba4d723d8442f9d8 to your computer and use it in GitHub Desktop.
Check if two strings are anagrams
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var testCases = [ | |
["aab", "baa"], | |
["bac", "bbc"] | |
]; | |
var isAnagram = function(first, second) { | |
return ( | |
first.split("").sort().join("") === second.split("").sort().join("") | |
); | |
}; | |
for (var tcIndex = 0; tcIndex < testCases.length; tcIndex++) { | |
var testCase = testCases[tcIndex]; | |
console.log("Test case: \"%s\", is anagram: %s", testCase.join(" "), (isAnagram(testCase[0], testCase[1]) ? "yes" : "no")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment