Can anyone help me with this query? I have an array of objects that need to be separated into repeating and non-repeating objects based on the segments they belong to, each in a separate array. For example-
[ {name:"abc",id:1,segments:[1,2]}, {name:"abc1",id:2,segments:[1]}, {name:"abc3",id:3,segments:[1,2]}, {name:"abc2",id:4,segments:[1,2,3]} ]
The resulting unique array should be -
uniqueArr = [{ name:"abc1",id:2,segments:[1]},{ name:"abc2",id:4,segments:[1,2,3]}]
- The example above is for non-repeating objects in the given array
repeatedEle = [[{ name:"abc",id:1,segments:[1,2]},{ name:"abc3",id:3,segments:[1,2]}]]
- The example above is for repeating objects in the given array based on the number of occurrences of the same segments.
- Repeated elements must be within a nested array.