XML Feeds

.

[javascript-dev] many floats many inlets problem.

volker böhm vboehm at gmx.ch
Sun Mar 30 03:59:48 MDT 2008


On 30 Mar 2008, at 00:43, Adam Chambers wrote:
>
> Im really confusing myself here although the answer is probs  
> simple, any help would be much appreciated.
>
> I have 15 floats all constantly changing, i need to find the  
> largest and more importantly which one of the float objects sent  
> the largest number so i can use it to trigger a specific msg. I  
> need it to be a constantly changing thing.
>
> I tried using an array to store all the numbers and then using sort 
> () etc but the problem is I need to know which of the fifteen float  
> objects sent the largest number.

you don't have to sort the whole array. simply search the max value  
and output it's arrayindex.

in case you are still unsure how to preceed, here is a working script.
btw, Ltop from Lobjects does exactly what you want.


outlets = 2;
function list() {	
	var input = arguments;	
	var max = Number.NEGATIVE_INFINITY;
	var pos = 0;		
	for(i=0; i<input.length; i++) {		
		if(input[i] > max) {
			max = input[i];
			pos = i;
		}
	}
	outlet(1, pos);
	outlet(0, max);
}



// volker.


More information about the javascript-dev mailing list