I have an array I need to group them based on size_y;
[
{"col":4,"row":1,"size_x":1,"size_y":4},
{"col":2,"row":2,"size_x":1,"size_y":2},
{"col":1,"row":1,"size_x":3,"size_y":1},
{"col":1,"row":4,"size_x":3,"size_y":1},
{"col":1,"row":5,"size_x":4,"size_y":1}
]
Now, if size_y is 4 I want to group all the rows less than or equal to 4.
[
{"col":4,"row":1,"size_x":1,"size_y":4},
{"col":2,"row":2,"size_x":1,"size_y":2},
{"col":1,"row":1,"size_x":3,"size_y":1},
{"col":1,"row":4,"size_x":3,"size_y":1},
],
[
{"col":1,"row":5,"size_x":4,"size_y":1}
]
thanks in advance.
Using pure JS you can simply do using reduce
You can use a generator function and
.splice()