Most occurring value in an array

Any ideas on a way of returning the value in an array that occurs the most (ideally without getting super complicated)?

Hola!

Would you like a No-Code or a Low-Code solution? :wink:

Hi :slight_smile:

I am open to either, provided performance in Glide is fast and reliable.

1 Like

Ok!
We can start using this trick but changing a little the code.

And I think it can be what you were looking for… right?

const arr=p1.split(",");
let maxFrec=-1;
let maxItem

arr.forEach((item) => {
   x= arr.filter(function(value)  {
       return value == item;
   }).length 
  
   if (x> maxFrec) {
      maxFrec=x;
      maxItem= item;
   }
})
return maxItem

As you can see in my code/example, I am not using an array of items already created. Instead, I use a list of items (almost the same) to work with it in my code and find what we are needing. We have to do this because of Glide’s JavaScript plugin doesn’t support an array as parameter so far. :face_with_diagonal_mouth:

I hope it helps you.

Saludos!

2 Likes