Currently working on some jasmine testing in JS. I've created a testing function that looks good so far (only running the first test at the moment).
describe('Anagram', function() {
it('no matches',function() {
var subject = new Anagram('diaper');
var matches = subject.matches([ 'hello', 'world', 'zombies', 'pants']);
expect(matches).toEqual([]);
});
Next, I have my simple function
var Anagram = function(string){
this.word = string;
};
Anagram.prototype.matches = function(array){
var answer = [];
var splitWord = this.word.split('').sort();
for(var i = 0; i < array.length; i++){
var isAnagram = true;
var splitItem = array[i].split('').sort();
for(var j = 0; j < splitWord.length; j++){
if(splitWord[j] !== splitItem[j]){
isAnagram = false;
}
}
if(isAnagram === true){
answer.push(array[i]);
}
}
return answer;
};
module.export = Anagram;
My function is designed to take a string and then analyze an array of strings to return any anagrams present. However, I keep encountering a TypeError: Anagram is not a function. I've searched for solutions and most suggestions point to semi-colons, but I believe I've used them correctly after variable and method declarations. I'd appreciate insights into what this typeError signifies, whether it is common, and what the likely causes might be.