Ad
  • Custom User Avatar

    Thanks you. But I do not understand why 0 at the end is taken as the initial value or why and empty array causes an error you wont pass with "type checking" number == []

  • Default User Avatar

    Very old chain, but for new readers: if you don't pass the 0 at the end, the first value of your array will be taken as the initial value of the accumulator and won't be modified by the (n*n) part.

  • Custom User Avatar

    If an initial value is provided to the reduce method, the first argument is the initial value and the second argument is the value of the first (!) element in the array.
    If an initial value is not provided, the first argument is the value of the first element in the array and the second argument is the value of the second (!) element in the array.

  • Default User Avatar

    You passed 0 in for the initial value. Is this required? In my solution, I omitted the 0 and it worked well; can you explain where omitting the 0 could cause a problem?

  • Default User Avatar

    Thanks for sharing your insight!

  • Default User Avatar

    Did some research on how you used the underscore in the callback function. The callback function is provided an 'index', 'element' and 'array object' parameter values. Per my research, some developers use the underscore to store the value, though essentially say it's not going to be used. Is this correct, or is there some other reason why you're using the underscore? (Wouldn't it be easier to omit the underscore?) Thanks!