Created
February 10, 2015 21:50
-
-
Save mecampbellsoup/18627d5aa85ff87c14e8 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
| var anagram = require('./anagram'); | |
| describe('Anagram', function() { | |
| it("no matches",function() { | |
| var subject = anagram("diaper"); | |
| var matches = subject.matches([ "hello", "world", "zombies", "pants"]); | |
| expect(matches).toEqual([]); | |
| }); | |
| }; |
Author
Author
function Anagram (input) {
this.input = input;
this.matches = function () {
// logic goes here...
};
}
var anagram = function(input) {
return new Anagram (input);
};
module.exports = anagram;Nice! That's most of the way there.
The better approach to matches is to put on the prototype of the function.
function Anagram (input) {
this.input = input;
}
Anagram.prototype.matches = function () {
// logic goes here...
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@scottluptowski, how can I make a JS object that can be initialized with an argument (in the above example that's the
anagram("diaper")bit) and subsequently that object responds to another methodmatcheswhich introspects the object's property where we stored the string"diaper"initially?