Ad
  • Custom User Avatar

    Hi! I found that new Array(3) is not produce [undefined, undefined, undefined]. It produced [ <3 empty items> ]. And we are cannot to interact with it by Array.prototype methods. We must to convert it to array with Array.from for example.

    > new Array(10)
    [ <10 empty items> ]
    > Array.from(new Array(10))
    [ undefined,
      undefined,
      undefined,
      undefined,
      undefined,
      undefined,
      undefined,
      undefined,
      undefined,
      undefined ]
    
  • Default User Avatar

    The finalArray variable you declare is redundant ;)

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    Thanks a lot! Totally forgot about it!

  • Default User Avatar

    There is a difference between the value undefined and the string 'undefined'

    See this for more info undefined

  • Default User Avatar

    Thanks everyone, your explanations helped me a lot.

  • Custom User Avatar

    You can create arrays like that: new Array(n), where n is quantity of elements. For example, new Array(3) will produce [undefined, undefined, undefined]. Besides, every array has join method, which creates a string from the array's elements and join's argument will play as separator, so that [1,2,3].join('anyStringYouLike') will be evaluated in '1anyStringYouLike2anyStringYouLike3'. And [undefined, undefined, undefined].join('String') will be evaluated in 'StringString'.

    Hope this explanation will help to undestand this solution.

  • Custom User Avatar

    I believe Array is a class, and when passed a number like this, it returns an empty array of size n + 1 (empty meaning, each element is undefined).

    Example:

    a = Array(3)
    [ , , ]
    a.length
    3
    a[0]
    undefined
    a.join('hi')
    'hihi'

  • Default User Avatar

    Could someone please explain what's going on here?
    Array(n+1).join(str)

    I couldn't find anything on the net about Array() taking parameters. Is that an object or a method or what?

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    I have the same issue, could you please help me with it, if you know an answer? Thanks.

  • Default User Avatar

    The same issue: Expected: 10184.37, instead got: 10184.37
    Fixed.
    Hint : check the type of result. it should be Number, not String

  • Default User Avatar

    When I try my code in console it works and pass all the tests, but inside codewars environment it brings only "Test didn't pass: Unknown error" text without any explanation.