I am working on a project in which the client sends us an array having some objects, there can be duplicate objects in the request as well. We determine the duplicate object based on the key called code. Here's an example:
[ {code: 10}, {code: 10}, {code: 10}, {code: 20}, {code:30} ]
In the example array above, we have 3 duplicate objects i.e., {code: 10}
We need to send this request to a third-party API, which accepts an array as well. The problem is that, in a single request to this API, we can't send duplicate objects. So we need to break this array provided by the client to a subarray, and then send each array to the API. If we break the sample provided above, we can get
[ [ {code: 10}, {code:20}, code:30} ], [ {code:10} ], [ {code:10} ] ]
So, in each of the subarray, we have unique objects (not duplicated) Also, we have a condition that the very first subarray, should contain all of the unique objects provided in the request by the client.
So, if we have a request from the client something like
[ {code: 10}, {code: 10}, {code: 10}, {code:20}, {code:20}, {code:30} ]
then the minimum subarray should be
[ [ {code: 10}, {code: 20}, {code:30} ], [ {code: 10}, {code:20} ], [ {code: 10} ] ]
can anyone help me here how can I break the array-like this? thank you