Skip to content

Instantly share code, notes, and snippets.

@jgdovin
Created April 17, 2015 02:06
Show Gist options
  • Save jgdovin/2583d70b76436257aab8 to your computer and use it in GitHub Desktop.
Save jgdovin/2583d70b76436257aab8 to your computer and use it in GitHub Desktop.
function Anagram(word) {
this.word = word.toLowerCase();
function matches(words) {
if(Array.isArray(words)) {
return words.filter(isAnagram);
} else {
return Array.prototype.slice.call(arguments).filter(isAnagram);
}
}
function isAnagram(word) {
word = word.toLowerCase();
return word !== this.word && sort(this.word) === sort(word);
}
function sort(word) {
return word.split("").sort().join("");
}
return {matches:matches}
}
module.exports = Anagram;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment