Skip to content

How to count matching values in array

agershun edited this page Dec 28, 2014 · 1 revision

How to count matching values in array?

Source: StackOverflow.com

Question

What is a any good algorithm/code to get list of unique values from array and count of its occurrence in array?

Answer

The example:

    var data = [1,2,3,4,3,2,3,4,5,3,2,1,1,1,2];

    var res = alasql('SELECT INDEX _, COUNT(*) FROM ? GROUP BY _',[data]);

You can try this example at jsFiddle;

Clone this wiki locally