reduce() and merge()

Certified Associate Developer

Hello,

I'm preparing to take a certification exam, and I'm struggling to find a use case that would help me better understand functions reduce() and merge(). Can you help a brother out?

  Discussion posts and replies are publicly visible

Parents
  • +1
    Certified Lead Developer

    For the merge, the documentation seems pretty self explanatory. It merges lists.

    As for the reduce function, this will probably explain it better than I can:

  • 0
    Certified Associate Developer
    in reply to Mathieu Drouin

    Thank you, but I might have explained my problem wrong.

    I could not come up with a use case, where merge() would be superior over, for example, append() or insert()? I know there's a difference in how these work, but if our goal is just to join arrays, then we have other functions that can accomplish that as well. I wanted to know whether there are cases in which merge() is an objectively better choice, rather than a matter of preference, which seems to be the case when speaking about combining arrays.

    With reduce(), again, I understand the premise, but I struggle to find a practical use case that would help me test my understanding of the function.

Reply
  • 0
    Certified Associate Developer
    in reply to Mathieu Drouin

    Thank you, but I might have explained my problem wrong.

    I could not come up with a use case, where merge() would be superior over, for example, append() or insert()? I know there's a difference in how these work, but if our goal is just to join arrays, then we have other functions that can accomplish that as well. I wanted to know whether there are cases in which merge() is an objectively better choice, rather than a matter of preference, which seems to be the case when speaking about combining arrays.

    With reduce(), again, I understand the premise, but I struggle to find a practical use case that would help me test my understanding of the function.

Children