array_count_values in Actionscript

In PHP there is a very useful function called array_count_values. It sorts an array by returning a 2 dimensional array consisting of non duplicate elements as keys, and values determined by how many times these elements appeared in the original array.

So, for example, an array [“red”,”green”,”blue”,”red”] would be converted into [“red” => 2, “green” =>1, “blue” => 1]. Duplicate elements are removed and the new array indicates how many times each, now unique value occurred in the array.

Unfortunately, Actionscript has no such function built in, so I made one. It is a modification of Senocular’s array.unique() prototype (which you can find in his Actionscript library), however rather than simply returning a unique array, it returns the 2 dimensional array mentioned above. Read : AS2 Array count values »

Posted on 20 Jun 2007
Posted in
Tagged
2 Comments
0 Trackbacks

About me

Soulwire is a weblog by Justin Windle; a Creative Technologist at Lean Mean Fighting Machine, London – I often Tweet, Flik, Link and Vim.

Twitter <follow>

March 12th 2010 - 11:17am

Live - Bahrain GP practice http://bit.ly/dBcV8m #F1