Ad
  • Default User Avatar

    you have something like: [1, -1, 6, -6, 5]
    the reduce method give the number's sum, in this case it will be 5, and this is the correct answer.
    But there is a problem maybe you have something like [1, -1, 6, -6, 5, 5], in this case the sum will be 10, because we have an additional 5, to avoid that, he has removed all the duplicated numbers in the array converting it to Set type