Math block: "min/max" of a list of values

I don't really understand the sense of those functions "min"/"max" from the math blocks. For finally only a few values its use is possible. But what if you want to determine the maximum of 1000 values? I don't know how to use it then if I don't want to write a seperate function that can do this. Those functions do not accept a list but only single values, each of them separately plugged in.

Who can help me?


So how hard was that?

2 Likes

Oh, that's good solutions! Thank you very much for this elegant alternative - incorporating the "min" into a loop. Actually I should have found that way by myself after having wondered about its senseful use for a long time.
(In the JS description/reference there is the "..." spread operator but this doesn't work in AI.)

I forgot to mention, if you have 1000 values, you might consider SQL.
There are workable SQLite extensions for AI2.

1 Like

You can get the maximum, minimum, order ... using JavaScript, check these websites:

In this example, 9 non-repeating random numbers of 50 eligible are generated, using an extension, we get the numbers in a string separated by commas.

[If you get the numbers from a list, you can pass the list to a comma separated string using the block: join items using separator ,]

I use two methods:
ooooooooooooooooooooooooooooooooooooooooooooooooooooo

window.AppInventor.setWebViewString("

gobal random

".split(",").sort(function(a,b) { return b - a; }).toString());

oooooooooooooooooooooooooooooooooooooooooooooooooooo

window.AppInventor.setWebViewString(Math.max.apply(Math,[

gobal random

]).toString());
ooooooooooooooooooooooooooooooooooooooooooooooooooooo

p162_javascript_mayor_2.aia (8.9 KB)

1 Like

Yes, very interesting. Muchas gracias, Juan Antonio, for posting these options. Apart from this, during the last months I intensively delt with JS/HTML that I had only rudimentary knowledge of before. Now I understand what happens if a page is loaded from AI (was hard work for me to analyse it) and how to write to the page's script. I found some ways for a comfortable use of the "RunJavaScript"-block as well as I created, to my opinion, an interesting routine to edit tables created in AI but edited using the WebView-component. I'm going to prepare them for further publishing here.
Jörg

I don't understand what is Visorweb1 and how you insert it in the project

"VisorWeb1" is "WebViewer1", I have changed it here:

p162i_javascript_mayor_2.aia (8.8 KB)

2 Likes

Thank you Antonio