Created
April 17, 2015 02:06
-
-
Save jgdovin/2583d70b76436257aab8 to your computer and use it in GitHub Desktop.
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
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