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

    And it removes the need to square only the first element in the array passed to reduce as first previous value.

  • Custom User Avatar

    It would cause a problem with an empty list.