How to count duplicates occurrences from an array of refs

Hi, firstly I want to thank your help.

I’m struggling of how to count the duplicate occurrences from this array:

I have this array from several inquiries.

[
  Ref(Collection("x"), "305800919607411200"),
  Ref(Collection("x"), "305800919607411200"),
  Ref(Collection("x"), "305800919607411201"),
  Ref(Collection("x"), "305800919607411201"),
  Ref(Collection("x"), "305800919607411201")
]

I’m expecting an output like:

[
  Ref(Collection("x"), "305800919607411200"), 2,
  Ref(Collection("x"), "305800919607411201"), 3
]

I’m not able to do it on my function.
In JS, I would use a reduce method, but I tried the logic using fauna Reduce, but I can’t.

Is there a kind hand to help me with this?

Thank you a million.

I have turned the logic of it, and now I’m getting the expected results.

[
  [ Ref(Collection("x"), "305800919607411201"), 3 ],
  [ Ref(Collection("x"), "305800919607411200"), 2 ]
]

Thanks anyway!

2 Likes

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.