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

Peter M. Brigham pmbrig at gmail.com
Sun Oct 11 22:26:53 EDT 2015


function getMaxLessThan tList,maxVal
   repeat for each item i in tList
      if i < maxVal then put i & comma after outList
   end repeat
   return max(item 1 to -1 of outList)
end getMaxLessThan

Simple and fast.

-- Peter

Peter M. Brigham
pmbrig at gmail.com
http://home.comcast.net/~pmbrig

On Oct 11, 2015, at 12:15 PM, Dr. Hawkins wrote:

> 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