Return Total of a Given Repeated Number in a List
Terry Judd
terry.judd at unimelb.edu.au
Thu May 23 23:47:38 EDT 2024
Probably not the shortest approach, but I’d probably do either this…
function countItemRepsInList pList, pItem
replace comma with cr in pList
filter pList with pItem
return (the number of lines in pList)
end countItemRepsInList
or this
function countItemRepsInList pList, pItem
put 0 into tCount
repeat for each item tItem in pList
if (tItem = pItem) then add 1 to tCount
end repeat
return tCount
end countItemRepsInList
Terry
From: use-livecode <use-livecode-bounces at lists.runrev.com> on behalf of Roger Guay via use-livecode <use-livecode at lists.runrev.com>
Date: Friday, 24 May 2024 at 12:09 PM
To: How to use LiveCode <use-livecode at lists.runrev.com>
Cc: Roger Guay <irog at mac.com>
Subject: Return Total of a Given Repeated Number in a List
Hi all,
Please, what’s the easiest way to return the total number of a given repeated number in a list of numbers? IOW, how many times is 2 repeated in a list containing 1,2,3,2,4,2,5,2,8 etc. Appreciate your help.
Thanks,
Roger
_______________________________________________
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
More information about the use-livecode
mailing list