Help with Arrays

Phil Davis revdev at pdslabs.net
Mon Oct 14 17:20:13 EDT 2013


Oops. See below.

On 10/14/13 2:16 PM, Phil Davis wrote:
> Hi Bill,
>
> Here is a clunky and simplistic way that works:
>
> on mouseUp
>     -- get the number of occurrences for each name
>     put myList() into tList
>     repeat for each line tLine in tList
>         add 1 to tCountsByName[tLine]
>     end repeat
>
>     -- reformat the 'counts' data
>     combine tCountsByName with CR and "="
>     sort lines of tCountsByName word 1 to -2 of each -- the minor sort
should be:
         sort lines of tCountsByName by 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!
>     answer tCountsByName
> end mouseUp
>
>
> function myList
>     get "Bill,Mary,Bill,John,Jim,Jane,Bill,Jim,Jane"
>     replace comma with CR in it
>     return it
> end myList
>
>
> HTH -
> Phil Davis
>
>
> 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:
>>     Bill
>>     Mary
>>     Bill
>>     John
>>     Jim
>>     Jane
>>     Bill
>>     Jim
>>     Jane
>>
>> 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?
>>
>> Thanks,
>> Bill Vlahos
>> _______________________________________________
>> use-livecode mailing list
>> use-livecode at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your 
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>
>

-- 
Phil Davis





More information about the Use-livecode mailing list