OriginalPostID-144331
Discussion posts and replies are publicly visible
Not that this thread isn't already ancient, but since it's been brought back up, I'll post the updated version of my old function that gets duplicate array members (now we have a!forEach and don't require sub-functions).
Note: this funciton returns ALL duplicate members, i.e. any and all array members that have a duplicate anywhere else in the array. If the need is for a list where each duplicate member appears only once, this result can be further de-duplicated.
with( local!uniqueMembers: rule!GLBL_removeDuplicateArrayMembers( array: ri!array ), /* note: this funciton does "union(ri!array, ri!array)". it's useful to have as a global function. */ local!indicesIfMultiple: a!forEach( items: local!uniqueMembers, expression: with( local!indices: wherecontains( fv!item, ri!array ), if( rule!APN_arrayLength(local!indices) > 1, local!indices, {} ) ) ), index( ri!array, sort(local!indicesIfMultiple), {} ) )
I do apologize, but for the sake of others I have to call out my alarm at a suggested answer which features the undocumented sort() function. (I don't understand why such a thing wouldn't be documented, but there you go)
It's correct from a certain perspective. This preserves the number of times an item has been duplicated. It's actually exactly what I was looking for.
It is not correct based on the example provided in the original question. I'm glad it helped you out, though.