Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bytorbrynden/ea8c13abe2abcbf4ba4d723d8442f9d8 to your computer and use it in GitHub Desktop.
Save bytorbrynden/ea8c13abe2abcbf4ba4d723d8442f9d8 to your computer and use it in GitHub Desktop.
Check if two strings are anagrams
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