javascript - Get the item that appears the most times in an array -


var store = ['1','2','2','3','4']; 

i want find out 2 appear in array. how go doing that?

i like:

var store = ['1','2','2','3','4']; var frequency = {};  // array of frequency. var max = 0;  // holds max frequency. var result;   // holds max frequency element. for(var v in store) {         frequency[store[v]]=(frequency[store[v]] || 0)+1; // increment frequency.         if(frequency[store[v]] > max) { // frequency > max far ?                 max = frequency[store[v]];  // update max.                 result = store[v];          // update result.         } } 

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -