it("should know properties that are functions act like methods", function() {
var meglomaniac = {
mastermind : "Brain",
henchman: "Pinky",
battleCry: function(noOfBrains) {
return "They are " + this.henchman + " and the" +
Array(noOfBrains + 1).join(" " + this.mastermind);
}
};
var battleCry = meglomaniac.battleCry(4);
expect('They are Pinky and the Brain Brain Brain Brain').toMatch(battleCry);
});
What is the definition of Array in this code (line 7)? I looked it up and it looks like it's an Array.of() command which generates an empty array of length n which in this case would be 5? So why does it end up with only 4 brain inputs assuming that is the correct assumption? Or is this array() doing something else?