Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5 Brains, not 4 #52

Closed
danninemx opened this issue Jun 29, 2015 · 2 comments
Closed

5 Brains, not 4 #52

danninemx opened this issue Jun 29, 2015 · 2 comments

Comments

@danninemx
Copy link

AboutObjects.js line 32 has an expected answer of "They are Pinky and the Brain Brain Brain Brain" -- with 4 iterations of the string "Brain".

The actual pseudo code is:

var megalomaniac = {
  mastermind : "Brain",
  henchman: "Pinky",
  battleCry: function (noOfBrains) {
    return "They are " + this.henchman + " and the" +
      Array(noOfBrains + 1).join(" " + this.mastermind);
  }
};

The problem in question was:

var battleCry = megalomaniac.battleCry(4);

If we indeed pass 4 as noOfBrains, since the method adds 1 to noOfBrains before joining them, would the result not have 5 "Brain"?

@endrin
Copy link

endrin commented Jun 30, 2015

No. Actually, Array(noOfBrains + 1) creates 5-element array of undefined which is then joined together with " Brain". As there are five elements there will be four joins.

@danninemx
Copy link
Author

That makes sense. Thank you.

uabandit pushed a commit to uabandit/javascript-koans that referenced this issue Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants