I have an array sorted as shown below. each element in the array is an object contains several properties. one of these properties is called "priorityTag". according to the code belwo, i am sorting the the array according to the priorityTag in each object. The code works properly.
some of the objects contains the same priorityTag. what i am trying to do is, to group the similar objects that contains the same priorityTag together.
for example, if the array contains the following:
example
arr[{prop1: "aaa1", prop2:"yas1", priorityTag:100},//group1
{prop1: "aaa2", prop2:"yas2", priorityTag:200},//group2
{prop1: "aaa3", prop2:"yas3", priorityTag:100},//group1
{prop1: "aaa4", prop2:"yas4", priorityTag:200},//group2
{prop1: "aaa5", prop2:"yas5", priorityTag:300},//group3
{prop1: "aaa6", prop2:"yas6", priorityTag:400},//group4
{prop1: "aaa7", prop2:"yas7", priorityTag:300},//group3
{prop1: "aaa8", prop2:"yas8", priorityTag:400},//group4
{prop1: "aaa9", prop2:"yas9", priorityTag:500},//group5
{prop1: "aaa10", prop2:"yas10", priorityTag:700},//group6
{prop1: "aaa11", prop2:"yas11", priorityTag:700},//group6
]
I want to get an array contains of groups of the objects that have the same priorityTag.
I want to have Array of Arrays.each element in the main Array is Array(s) contains the the object(s) that has the same priorityTag
Please let me know how to do that correctly
code
sortFeaturesPerPriority2(arr) {
logger.debug('[sortFeaturesPerPriority2]: Array.isArray(arr):', Array.isArray(arr));
logger.debug('[sortFeaturesPerPriority2]: arr:', arr);
logger.debug('[sortFeaturesPerPriority2]: arr.length:', arr.length);
arr.sort((a, b) => a.getPriorityTag() - b.getPriorityTag());
logger.debug('[sortFeaturesPerPriority2]: arr.sort:', arr);
return arr;
}