min() and array

Mike Bonner bonnmike at gmail.com
Thu May 5 18:24:58 CEST 2016

```You're only looking at a single value, so its returning it.
min(tArray[i][v])  especially right after your loop.. i will be 5, and v
being unset is seen as "v"
the value that was placed into tArray[i]["v"] was 15.
The min of 15 is 15.

Even if your v has been set, you'd still be only looking at a single value,
which would be returned as the minimum.

In your first example, tArray[v] will be seen as tArray["v"] unless v is
set to something, but no matter how you look at it, tArray[v] is a single
value, and in this case will will be empty.  tarray["anythinghere"] will be
empty because nothing was placed into that element of the array.

Now, if each element [i][v] contains a list "3,5,2,24,63" min([i][v] would
return 2 as the minimum.

To get the minimum value across array entries you need to iterate through
them.

In this case, since v is "v" and never changes you'd have to do something
like this..

repeat for each key tKey in tArray
if tMin is empty then
put tArray[tKey][v] into tMin
else
if tArray[tKey][v] < tMin then put tArraytKey][v] into tMin
end if
return tMin

Alternatively you could return the keys that point to tMin which might be
more useful.

On Thu, May 5, 2016 at 9:04 AM, Richard Gaskin <ambassador at fourthworld.com>
wrote:

> Ludovic THEBAULT wrote:
>
> >> Le 4 mai 2016 à 21:46, Paul Dupuis:
> >>
> >> On 5/4/2016 2:47 PM, Ludovic THEBAULT wrote:
> >>> repeat with i=1 to 5
> >>>   put 10 + i into tarray[i][v]
> >>> end repeat
> >>> put min(tarray[v])
> >>
> >> You problem is with the second index on the array.
> >>
> >
> > Thanks.
> >
> > Too bad that this function don’t work with second index.
>
> It does if you script for it:
>
>   put min(tArray[i][v]
>
>
> Interestingly, no matter which variant I try the value I see in v8.0 is
> 15, which is the max not the min.  Anyone else seeing that?
>
> --
>  Fourth World Systems
>  Software Design and Development for the Desktop, Mobile, and the Web
>  ____________________________________________________________________