Finding max value of a set of variables having integer values

Hi,

I have a set of ten variables b1 … b10 and want to find the maximum value, I found the operator maxall but have not figured out how to use it when my starting point is a set of variables rather than a filter to be run on tiddlers or their fields.

So for instance I have the value of b8 via a function - similar for the other variables.

\function count80to90()
[all[tiddlers]!is[system]has:field[rating3]get[rating3]compare:integer:gt[80]compare:integer:lteq[90]count[]]
\end
<$let b1=<<count1to10>> b2=<<count10to20>> .... etc ... >

So now I want to apply maxall to b1 through to b10 in order to find the maximum integer value so that I can scale the Y axis of a bar graph.

Thanks …

The “brute” way is to get the value of each variable using a set of filter runs, followed by the maxall[] filter, like this:

<$let max={{{ [<b1>] [<b2>] [<b3>] [<b4>] [<b5>] [<b6>] [<b7>] [<b8>] [<b9>] [<b10>] +[maxall[]] }}}>

A more compact way is to generate the variable names and use getvariable[] to fetch their values, and then apply the maxall[] filter, like this:

<$let max={{{ [range[10]addprefix[b]getvariable[]] +[maxall[]] }}}>
3 Likes

When you don’t have an adequate pattern to retrieve the variable values, you can always resort on applying the getvariable[] operator to the list of all variable names. As in:

{{{ b1 b2 b3 ... :and[getvariable[]] :and[maxall[]] }}}

Addendum: as one should have expected, Eric’s answer is more complete, and offers as a bonus an elegant way to compute those names!

1 Like

Thanks xcazin and Eric, you both came to the same place, it seems to work just fine :grinning: