Most occurring value in an array

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