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

Geoff Canyon gcanyon at gmail.com
Tue Oct 13 00:32:13 EDT 2015

```Interesting. What exact code did you use? Here's mine:

on mouseUp
repeat 1000000
put random(1000000000),"" after L
end repeat
put the long seconds into T
get greatestLessThanSort(L,500000000)
put "sort" && (the long seconds - T) && it into fld 3

put the long seconds into T
get greatestLessThanRepeat(L,500000000)
put cr & "repeat" && (the long seconds - T) && it after fld 3
end mouseUp

function greatestLessThanSort pList,V
sort items of pList descending numeric
sort items of pList by each >= V
return item 1 of pList
end greatestLessThanSort

function greatestLessThanRepeat pList,V
put empty into R
repeat for each item i in pList
if i < V and i > R then put i into R
end repeat
return R
end greatestLessThanRepeat

And the results:

sort 0.916539 499999879
repeat 0.331764 499999879

On Tue, Oct 13, 2015 at 12:07 AM, <dunbarx at aol.com> wrote:

> Geoff.
>
>
> I find this slower than the sort method. By about 30%.
>
>
> Craig
>
>
>
> -----Original Message-----
> From: Geoff Canyon <gcanyon at gmail.com>
> To: How to use LiveCode <use-livecode at lists.runrev.com>
> Sent: Mon, Oct 12, 2015 9:11 pm
> Subject: Re: function for greatest object in list less than or equal to a
> value
>
>
> Not quite as concise, but this function is about 3x faster:
>
> function
> greatestLessThan pList,V
>    put empty into R
>    repeat for each item i in
> pList
>       if i < V and i > R then put i into R
>    end repeat
>    return
> R
> end
> greatestLessThan
> _______________________________________________
> 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
>
>
> _______________________________________________
> 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
>

```