Ad
  • Custom User Avatar

    It's another case: A sum is initialized with 0 and then all elements are added to the sum. The average, on the other hand, is defined by the sum of all elements divided by the number of all elements, which would mean 0 (the sum) divided by 0 (the number of elements). And division by 0 means: NaN.

  • Custom User Avatar

    Why should that be better? If you have no values, you can't build an average, so you need to return a special value, since 0 is a valid result for values.