PDA

View Full Version : how get a math.max from an ArrayCollection?


ricoterox
08-08-2007, 03:06 PM
hi people ...

i have an ArrayCollection with a lot of number.....

i push this arraycollection with a xml (httpService)

how can i get a Math.max to this arrayCollection??

var MaxNumber = Math.max(myArrayCollection) ????

help pliz

ricoterox
08-08-2007, 05:07 PM
i use this for a simple array....

private function minimoGet2():void{
var dato:Number;
var miArray:Array = new Array(5,1,2,8,4,5,6,77);
for(var i:int=0; i<miArray.length; i++){
var arrayE:Object = new Object();
dato = Math.max.apply(this, miArray);
position3.text = String(dato);

}
}
--------> returns 77

but i want use that with a arraycollection....

how convert arraycollection to array..

toArray() ???

arraycollection.source ???

any help....... -.-

Jim Freer
08-08-2007, 05:51 PM
var lvArrayCollection:ArrayCollection = new ArrayCollection( [10,2,3,5,99,0] );

var lvNumber:Number = Math.max.apply( "", lvArrayCollection.source );

http://freerpad.blogspot.com/

ricoterox
08-08-2007, 06:39 PM
var lvNumber:Number = Math.max.apply( "", lvArrayCollection.source );

result --------> NaN

another ideas ........

Jim Freer
08-08-2007, 06:55 PM
Are you sure NaN isn't the correct answer? Is the ArrayCollection filled with numbers? With a non-sparse set of numbers it does work.

http://freerpad.blogspot.com/

ricoterox
08-08-2007, 07:18 PM
my array contains 4.15, 4.12, 4.15, 1.25, 1.58, 5.45, 2.35 ............


private function minimoGet():void{
var dato:Number;
var letras:String;

for(var i:int=0; i<serieCoti1.length; i++){
var arrayE:Object = new Object();
dato = Math.max.apply(this, serieCoti1.source);

//position3.text = String(dato);

}
arrayE.numerosp = dato;
ac_array.addItem(arrayE);
}

that returns ---- NaN


this is my source for serieCoti1 ---> http://www.invertironline.com/graficador/cotizaciones.asp?tid_titulo=2681

the item PRECULTI ... look the source ... its a xml

ideas ?

dr_zeus
08-08-2007, 07:30 PM
If it comes from XML, you may need to do some conversions to get the data into native Number format. Anything from XML is a String by default, and I imagine that's why Math.max() isn't working for you.

ricoterox
08-08-2007, 09:34 PM
private function copyArrat():void{
var dato:Number;
var datoM:Number;
var ruedas:Number = 14;
var unArray:Array = new Array();
for(var i:uint=0; i<ruedas; i++){
var items:Object = new Object();
serieCoti1.getItemAt(i).preculti;
items.num = serieCoti1.getItemAt(i).preculti;
unArray.push(items.num);
gridArray.dataProvider = unArray;

for(var e:int=0; e<unArray.length; e++){

var pEle:Object = new Object();
dato = Math.min.apply(this, unArray);
datoM = Math.max.apply(this, unArray);
position3.text = "Minimo" + dato;
position2.text = "Maximo" + datoM;
//}
pEle.numes = 100*(serieCoti1.getItemAt(i).preculti - dato)/(datoM - dato);
//ac_Estocastico.addItem(pEle);
ac_Estocastico.addItem(new Object());
ac_Estocastico.setItemAt(pEle,i);
estoc.text = "Cuenta " + 100*(serieCoti1.getItemAt(i).preculti - dato)/(datoM - dato);
}
}

}



Look this .....

its working .... but some result are NaN ..... another not....

its a litle weir .....

ricoterox
08-08-2007, 09:38 PM
this is the file .........

if you gona try in your flex

Jim Freer
08-08-2007, 09:51 PM
I'm not following what you are doing all that well, but try this:

items.num = Number( serieCoti1.getItemAt(i).preculti.toString() );

cfphpflex@gmail.com
06-13-2010, 09:12 PM
[Bindable]
private var items:ArrayCollection; // declare variable itmes as type ArrayCollection
private function init():void
{
items = new ArrayCollection();

items.addItem(new GetCalls("Homer", "lisa", 45));
items.addItem(new GetCalls("Marge", "homer", 5));

}

// loop through arraycollection called items
// declare searchResult array collection
var searchResult:ArrayCollection = new ArrayCollection;

function GetMatch():void {
for(var i:int = 0; i < items.length; i++)
{
if (items[i].callfrom == searchCallFrom.selectedItem.toString())
{ searchResult.addItem(new GetCalls(items[i].callfrom,items[i].callto,items[i].minutes));
}
}

// GetCalls Function
package
{
[Bindable] // bindable class for the collection
public class GetCalls

{
public var callfrom:String;
public var callto:String;
public var minutes:Number;

public function GetCalls(callfrom:String, callto:String, minutes:Number)
{
this.callfrom = callfrom;
this.callto = callto;
this.minutes = minutes;
}
}
}