Skip to content

Instantly share code, notes, and snippets.

@masautt
Created September 6, 2019 04:55
Show Gist options
  • Save masautt/2ec67e0cd0c580a6336034a99f46ed6a to your computer and use it in GitHub Desktop.
Save masautt/2ec67e0cd0c580a6336034a99f46ed6a to your computer and use it in GitHub Desktop.
How to check if 2 strings are anagrams in JavaScript?
function isAnagram (a, b) {
var y = a.split("").sort().join(""),
z = b.split("").sort().join("");
return (z === y)
}
console.log(isAnagram("marek", "kemra")) // --> true
console.log(isAnagram("sautter", "sautrra")) // --> false
// https://stackoverflow.com/questions/23785465/javascript-anagram-comparison
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment