I have an Array {1,2,3,4,4,5,3} . I want to know how many duplicate values are t

I have an Array {1,2,3,4,4,5,3} . I want to know how many duplicate values are there in that Array and the output should return the unique duplicate values like {3,4}. Is there a function to gets this output?

OriginalPostID-144331

OriginalPostID-144331

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    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),
        {}
      )
    )

Reply
  • 0
    Certified Lead Developer

    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),
        {}
      )
    )

Children