After receiving an array with a number of objects, my goal is to split it based on categories. Once the sum value of categories in the array reaches 15, I need to further divide the array as shown below for better organization.
Any assistance would be greatly appreciated
Array
[Object { name="A", categories=[2]}, Object { name="B", categories=[3]}, Object { name="C", categories=[1]}, Object { name="D", categories=[1]}, Object { name="E", categories=[1]}, Object { name="F", categories=[3]}, Object { name="G", categories=[1]}, Object { name="H", categories=[1]}, Object { name="I", categories=[1]}, Object { name="J", categories=[3]}, Object { name="K", categories=[2]}, Object { name="L", categories=[2]}, Object { name="M", categories=[2]}]
Additional Details
[{"name":"A","categories":["543","301"]},{"name":"B","categories":["100","120","390"]},{"name":"C","categories":["453"]},{"name":"D","categories":["112"]},{"name":"E","categories":["542"]},{"name":"F","categories":["534","545","547"]},{"name":"G","categories":[" 535"]},{"name":"H","categories":["390"]},{"name":"I","categories":["528"]},{"name":"J","categories":["101","492"," 320"]},{"name":"K","categories":["201","210"]},{"name":"L","categories":["102","573"]},{"name":"M","categories":["211","220"]}]
Desired Result
[[{"name":"A","categories":["543","301"]},{"name":"B","categories":["100","120","390"]},{"name":"C","categories":["453"]},{"name":"D","categories":["112"]},{"name":"E","categories":["542"]},{"name":"F","categories":["534","545","547"]},{"name":"G","categories":[" 535"]},{"name":"H","categories":["390"]},{"name":"I","categories":["528"]},{"name":"J","categories":["101"]}],[{"name":"J","categories":["492"," 320"]},{"name":"K","categories":["201","210"]},{"name":"L","categories":["102","573"]},{"name":"M","categories":["211","220"]}]]
This segment of the result will offer more guidance on achieving the desired outcome
{"name":"J","categories":["101"]}],[{"name":"J","categories":["492"," 320"]}