Ad
  • Custom User Avatar

    Because the constructor of Array takes the number of items in the list and Array.join joins the items together. This means that when you have 2 items you will only get 1 joined item. As seen in the following example:

    [1,2].join('-');

    This will return '1-2'. In the solution we create an empty array and join it with the letter. So if n is 2 and we join it without adding 1 we will get 'a' instead of 'aa'.