function for greatest object in list less than or equal to a value

dunbarx at aol.com dunbarx at aol.com
Sun Oct 11 22:26:54 EDT 2015


Richard,


How about this, given a comma delimited list (say "1,1,2,2,3,3,4,4,5,6,7,8,9") in a field 1, with a "5" as your index?



on mouseUp
  answer findItemLessThanIndex(fld 1,"5")
end mouseUp


function findItemLessThanIndex tData,tIndex
   put comma & tIndex after tData
   sort items of tData numeric
   return  item itemOffset("5",tData) -1 of tData
end findItemLessThanIndex




-----Original Message-----
From: Dr. Hawkins <dochawk at gmail.com>
To: How to use LiveCode <use-livecode at lists.runrev.com>
Sent: Sun, Oct 11, 2015 12:16 pm
Subject: function for greatest object in list less than or equal to a value


It would be nice to have an intrinsic for this, but I just read the
entire
function list . . .

I need to find the largest number in a list which
is smaller than a
specified value.

e.g., for the list "1,3,4,7,9" and 5, the
largest such value would be 4.

In a spreadsheet, I could use use vlookup()
and specified the index as the
row to return.

In a database, could " SELECT
MAX(myVar) WHERE myVar<5;", and so forth

I  had thought that FILTER could
take a]b arbitrary function, but
apparently not. t It could conceivably use a
rgexp, but calling a regex for
numeric comparison "ugly" would be polite

I'm
not seeing anyhing better than lo better than looping through at the
moment
--

Dr. Richard E. Hawkins, Esq.
(702)
508-8462
_______________________________________________
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