Sorted Union - anyone managed to use Array.reduce()?

I’m a bit lost with this one. Arguments come back more complicated that the input.
eg )

([1, 3, 2], [5, 2, 1, 4], [2, 1]) = [[1, 3, 2], [1, [5]], 1, [[1, 3, 2], [1, [5]], [2, [4]]]]

Creating a union of two sets is a binary operation, meaning that it needs two operands and returns one value. reduce takes a function with two arguments, which returns one value. What a coincidence… :wink:

Assume you have a sum-function taking two arguments and an array of numbers, like [2, 3, 7, 5, 8, 3]. This is what reduce does (not literally):

sum(3, sum(8, sum(5, sum(7, sum(2, 3)))));