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);
            }
       }
    
    }

 

 or register to reply.

Notify Moderator