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
    Hi Fariaj, if I understand your use case, you want to find and return the duplicate items in your array (e.g. findDuplicates({1,2,3,4,4,5,3, 3}) will return {3,4}. This is a quick way to do it I believe (keep in mind you'll probably need some null checks):

    TEST_isDuplicate:
    =length(wherecontains(ri!value, ri!array)) > 1

    Then the actual rule - TEST_findDuplicates:
    =with(
    local!input: {1,2,3,4,4,5,3},
    local!uniqueInputs: union(local!input, local!input),
    filter(rule!TEST_isDuplicate(_, local!input), local!uniqueInputs)
    )
Reply
  • 0
    Certified Lead Developer
    Hi Fariaj, if I understand your use case, you want to find and return the duplicate items in your array (e.g. findDuplicates({1,2,3,4,4,5,3, 3}) will return {3,4}. This is a quick way to do it I believe (keep in mind you'll probably need some null checks):

    TEST_isDuplicate:
    =length(wherecontains(ri!value, ri!array)) > 1

    Then the actual rule - TEST_findDuplicates:
    =with(
    local!input: {1,2,3,4,4,5,3},
    local!uniqueInputs: union(local!input, local!input),
    filter(rule!TEST_isDuplicate(_, local!input), local!uniqueInputs)
    )
Children
No Data