Help with Arrays
revdev at pdslabs.net
Mon Oct 14 23:16:09 CEST 2013
Here is a clunky and simplistic way that works:
-- get the number of occurrences for each name
put myList() into tList
repeat for each line tLine in tList
add 1 to tCountsByName[tLine]
-- reformat the 'counts' data
combine tCountsByName with CR and "="
sort lines of tCountsByName word 1 to -2 of each -- the minor sort
sort lines of tCountsByName numeric descending by last word of each
-- the major sort
replace "=" " (" in tCountsByName
replace CR with ")" & CR in tCountsByName
put ")" after tCountsByName
-- you're done!
replace comma with CR in it
On 10/14/13 1:52 PM, Bill Vlahos wrote:
> I have a list of names many of which repeat and I want to get a count of how many times each name appears in the list and sort it.
> This seems like a perfect example of using an array but I'm struggling to figure it out.
> Sample list:
> The popularity result should look like this:
> Bill (3)
> Jane (2)
> Jim (2)
> John (1)
> Mary (1)
> How would I do this using an array?
> Bill Vlahos
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
More information about the use-livecode