AG

Hello Everyone, 
I have an array of several eponymous occurrences of two (for example) definitions. How do I remove all duplicates with the same object name from the array? Aristata.Unique does not work in this case. Tell me please, is there some standard simple algorithm for such a case?

For example:

I have
[def1occ1,def1occ2,def1occ3]

Need
[def1occ<any>]

OR

I have
[def1occ1,def1occ2,def1occ3,def2occ1,def2occ2,def2occ3];

Need
[def1occ<any>, def2occ<any>];

I came up with this algorithm. Is there a simpler and more compact version?

    /*documentsPackage - an array with the same occurrences of one or more
definitions, from which duplicates must be removed*/

    for (var k=0;k<documentsPackage.length;k++){
        documentsNamesPackage[k] = documentsPackage[k].ObjDef().Name(gl);
    }    
    
    for (var l=0;l<documentsNamesPackage.length;l++){
        var count = 0;
        for (var n=0;n<documentsPackage.length;n++){
            if (documentsNamesPackage[l] == documentsPackage[n].ObjDef().Name(gl) && count == 0){
                count++;
                continue;
            } else if (documentsNamesPackage[l] == documentsPackage[n].ObjDef().Name(gl) && count != 0){
                documentsPackage.splice(n,n);
            }
       }
    
    }

 

by Robert Goldenbaum
Badge for 'Question Solver' achievement
Posted on Thu, 01/19/2023 - 08:45

Hi,

could be something like this:

mCheckMap =  new java.util.Hashtable();

for (i = 0; i < oObjOccList.length; i++){

   oObjOcc = oObjOccList[i];

   if (!mCheckMap.containsKey(oObjOcc.ObjDef().GUID())){

      mCheckMap.put(oObjOcc.ObjDef().GUID(), "");

      aoNewArray.push(oObjOcc)

   }

}

But perhaps you should go to ObjDef level instead from the beginning...

BR Robert

1
by Kay Fischbach
Posted on Fri, 01/20/2023 - 08:57

In reply to by Mangol

Another solution, leveraging

  • HashSet instead of HashMap since the map-values aren't used for anything useful anyways
  • JavaScript array.filter method
function filterOccsByDefinitionGUID(occsToFilter) {
    var guidSet = Packages.java.util.HashSet();
    
    function filterOcc(someOcc) {
        return guidSet.add(someOcc.ObjDef().GUID());
    }
    
    return occsToFilter.filter(filterOcc);
}

var selOccs = ArisData.getSelectedObjOccs();
var result = filterOccsByDefinitionGUID(selOccs);
0
by Andrey Gritsenko
Posted on Tue, 02/28/2023 - 13:12

Hi.

Javascript version

function getFirstObjOccArray(objOccs) {
    const firstOccList = objOccs.reduce(function (list, nextObjOcc) {
        const guid = nextObjOcc.ObjDef().GUID() + '';
        if (!(guid in list)) {
            list[guid] = nextObjOcc;
        };
        return list;
    }, {});
    return Object.keys(firstOccList).map(function (nextKey) {
        return firstOccList[nextKey];
    });
} // getFirstObjOccArray

 

1

Featured achievement

Question Solver
Share your expertise and have your answer accepted as best reply.
Recent Unlocks
  • CR
  • BH
  • Profile picture for user Ivan.Ivanov.softwareag.com
  • Profile picture for user mscheid
  • MS
  • PacMan

Leaderboard

|
icon-arrow-down icon-arrow-cerulean-left icon-arrow-cerulean-right icon-arrow-down icon-arrow-left icon-arrow-right icon-arrow icon-back icon-close icon-comments icon-correct-answer icon-tick icon-download icon-facebook icon-flag icon-google-plus icon-hamburger icon-in icon-info icon-instagram icon-login-true icon-login icon-mail-notification icon-mail icon-mortarboard icon-newsletter icon-notification icon-pinterest icon-plus icon-rss icon-search icon-share icon-shield icon-snapchat icon-star icon-tutorials icon-twitter icon-universities icon-videos icon-views icon-whatsapp icon-xing icon-youtube icon-jobs icon-heart icon-heart2 aris-express bpm-glossary help-intro help-design Process_Mining_Icon help-publishing help-administration help-dashboarding help-archive help-risk icon-knowledge icon-question icon-events icon-message icon-more icon-pencil forum-icon icon-lock