[flexcoders] Re: how to get an array as a part from another array?

2009-11-25 Thread turbo_vb
Could use a filterFunction.

-TH

--- In flexcoders@yahoogroups.com, coder3 rrhu...@... wrote:

 
 Hi All,
 
 I have a ArrayCollection, it contains id, name, sex, isSenior, etc.
 now i only need an array of id through that list. what's the quickest way
 to get an array of ids if isSenior is true, without using a loop?
 
 thanks
 
 C
 
 -- 
 View this message in context: 
 http://old.nabble.com/how-to-get-an-array-as-a-part-from-another-array--tp26519700p26519700.html
 Sent from the FlexCoders mailing list archive at Nabble.com.





[flexcoders] Re: how to get an array as a part from another array?

2009-11-25 Thread jamesfin


private function seniorsOnly(person:*, index:int, arr:Array):Boolean{
return (person.isSenior == true?true:false);
}


private function init():void{

var ac:ArrayCollection = new ArrayCollection([
{id:1, name:bob, sex:m, isSenior:true},
{id:2, name:kathy, sex:f, isSenior:false},
{id:3, name:joe, sex:m, isSenior:false},
{id:4, name:barb, sex:f, isSenior:true},
{id:5, name:pete, sex:m, isSenior:true}
]);


var seniors:Array = 
ac.toArray().filter(seniorsOnly);







--- In flexcoders@yahoogroups.com, turbo_vb timh...@... wrote:

 Could use a filterFunction.
 
 -TH
 
 --- In flexcoders@yahoogroups.com, coder3 rrhuang@ wrote:
 
  
  Hi All,
  
  I have a ArrayCollection, it contains id, name, sex, isSenior, etc.
  now i only need an array of id through that list. what's the quickest way
  to get an array of ids if isSenior is true, without using a loop?
  
  thanks
  
  C
  
  -- 
  View this message in context: 
  http://old.nabble.com/how-to-get-an-array-as-a-part-from-another-array--tp26519700p26519700.html
  Sent from the FlexCoders mailing list archive at Nabble.com.
 





[flexcoders] Re: how to get an array as a part from another array?

2009-11-25 Thread turbo_vb
Nope, going to have to loop and create the new array manually.  Even using a 
filterFunction is still looping; behind the scenes.

-TH

--- In flexcoders@yahoogroups.com, coder3 rrhu...@... wrote:

 
 by using a filter funtion can return you the array with isSenior==true;
 
 but i need an arry of id's only.
 in this case,
 i need an returned array like this: 
 [1, 4, 5]
 
 
 not
   [ {id:1, name:bob, sex:m, isSenior:true},
   {id:4, name:barb, sex:f, isSenior:true},
   {id:5, name:pete, sex:m, isSenior:true}
   ]
 
 
 can i do that without a loop?
 
 
 
 
 jamesfin-2 wrote:
  
  
  
  private function seniorsOnly(person:*, index:int, arr:Array):Boolean{
  return (person.isSenior == true?true:false);
  }
  
  
  private function init():void{
  
  var ac:ArrayCollection = new ArrayCollection([
  {id:1, name:bob, sex:m, isSenior:true},
  {id:2, name:kathy, sex:f, isSenior:false},
  {id:3, name:joe, sex:m, isSenior:false},
  {id:4, name:barb, sex:f, isSenior:true},
  {id:5, name:pete, sex:m, isSenior:true}
  ]);
  
  
  var seniors:Array = 
  ac.toArray().filter(seniorsOnly);
  
  
  
  
  
  
  
  --- In flexcoders@yahoogroups.com, turbo_vb TimHoff@ wrote:
 
  Could use a filterFunction.
  
  -TH
  
  --- In flexcoders@yahoogroups.com, coder3 rrhuang@ wrote:
  
   
   Hi All,
   
   I have a ArrayCollection, it contains id, name, sex, isSenior,
  etc.
   now i only need an array of id through that list. what's the quickest
  way
   to get an array of ids if isSenior is true, without using a loop?
   
   thanks
   
   C
   
   -- 
   View this message in context:
  http://old.nabble.com/how-to-get-an-array-as-a-part-from-another-array--tp26519700p26519700.html
   Sent from the FlexCoders mailing list archive at Nabble.com.
  
 
  
  
  
  
 
 -- 
 View this message in context: 
 http://old.nabble.com/how-to-get-an-array-as-a-part-from-another-array--tp26519700p26521572.html
 Sent from the FlexCoders mailing list archive at Nabble.com.





[flexcoders] Re: how to get an array as a part from another array?

2009-11-25 Thread turbo_vb
Seems like it might be about the same amount of code though:

var myIdArray:Array = [];

for each ( var myObject:MyObject in myArrayCollection )

{

  if ( myObject.isSenior ) myIdArray.push( myObject.id );

}




-TH



--- In flexcoders@yahoogroups.com, coder3 rrhu...@... wrote:


 right. filtering is a loop actually. but it just keep our code look
more
 clean.

 all right, i guest there is no short cut to get the partial array.

 thanks



 turbo_vb wrote:
 
  Nope, going to have to loop and create the new array manually.  Even
using
  a filterFunction is still looping; behind the scenes.
 
  -TH
 
  --- In flexcoders@yahoogroups.com, coder3 rrhuang@ wrote:
 
 
  by using a filter funtion can return you the array with
isSenior==true;
 
  but i need an arry of id's only.
  in this case,
  i need an returned array like this:
  [1, 4, 5]
 
 
  not
  [ {id:1, name:bob, sex:m, isSenior:true},
  {id:4, name:barb, sex:f, isSenior:true},
  {id:5, name:pete, sex:m, isSenior:true}
  ]
 
 
  can i do that without a loop?
 
 
 
 
  jamesfin-2 wrote:
  
  
  
private function seniorsOnly(person:*, index:int,
arr:Array):Boolean{
   return (person.isSenior == true?true:false);
  }
  
  
  private function init():void{
  
   var ac:ArrayCollection = new ArrayCollection([
   {id:1, name:bob, sex:m, isSenior:true},
   {id:2, name:kathy, sex:f, isSenior:false},
   {id:3, name:joe, sex:m, isSenior:false},
   {id:4, name:barb, sex:f, isSenior:true},
   {id:5, name:pete, sex:m, isSenior:true}
   ]);
  
  
   var seniors:Array = ac.toArray().filter(seniorsOnly);
  
  
  
  
  
  
  
   --- In flexcoders@yahoogroups.com, turbo_vb TimHoff@ wrote:
  
   Could use a filterFunction.
  
   -TH
  
   --- In flexcoders@yahoogroups.com, coder3 rrhuang@ wrote:
   
   
Hi All,
   
I have a ArrayCollection, it contains id, name, sex,
  isSenior,
   etc.
now i only need an array of id through that list. what's the
  quickest
   way
to get an array of ids if isSenior is true, without using
a
  loop?
   
thanks
   
C
   
--
View this message in context:
  
 
http://old.nabble.com/how-to-get-an-array-as-a-part-from-another-array--\
tp26519700p26519700.html
Sent from the FlexCoders mailing list archive at Nabble.com.
   
  
  
  
  
  
 
  --
  View this message in context:
 
http://old.nabble.com/how-to-get-an-array-as-a-part-from-another-array--\
tp26519700p26521572.html
  Sent from the FlexCoders mailing list archive at Nabble.com.
 
 
 
 
 

 --
 View this message in context:
http://old.nabble.com/how-to-get-an-array-as-a-part-from-another-array--\
tp26519700p26521778.html
 Sent from the FlexCoders mailing list archive at Nabble.com.




[flexcoders] Re: how to get an array as a part from another array?

2009-11-25 Thread jamesfin

too much fun


private var _arr:Array = new Array();

private function init():void{

var ac:ArrayCollection = new ArrayCollection([
{id:1, name:bob, sex:m, isSenior:true},
{id:2, name:kathy, sex:f, isSenior:false},
{id:3, name:joe, sex:m, isSenior:false},
{id:4, name:barb, sex:f, isSenior:true},
{id:5, name:pete, sex:m, isSenior:true}
]);

ac.toArray().filter(seniorsOnly);
}

private function seniorsOnly(person:*, index:int, 
arr:Array):Boolean{

return(person.isSenior?_arr.push(person.id):false);
}




--- In flexcoders@yahoogroups.com, turbo_vb timh...@... wrote:

 Seems like it might be about the same amount of code though:
 
 var myIdArray:Array = [];
 
 for each ( var myObject:MyObject in myArrayCollection )
 
 {
 
   if ( myObject.isSenior ) myIdArray.push( myObject.id );
 
 }
 
 
 
 
 -TH
 
 
 
 --- In flexcoders@yahoogroups.com, coder3 rrhuang@ wrote:
 
 
  right. filtering is a loop actually. but it just keep our code look
 more
  clean.
 
  all right, i guest there is no short cut to get the partial array.
 
  thanks
 
 
 
  turbo_vb wrote:
  
   Nope, going to have to loop and create the new array manually.  Even
 using
   a filterFunction is still looping; behind the scenes.
  
   -TH
  
   --- In flexcoders@yahoogroups.com, coder3 rrhuang@ wrote:
  
  
   by using a filter funtion can return you the array with
 isSenior==true;
  
   but i need an arry of id's only.
   in this case,
   i need an returned array like this:
   [1, 4, 5]
  
  
   not
   [ {id:1, name:bob, sex:m, isSenior:true},
   {id:4, name:barb, sex:f, isSenior:true},
   {id:5, name:pete, sex:m, isSenior:true}
   ]
  
  
   can i do that without a loop?
  
  
  
  
   jamesfin-2 wrote:
   
   
   
 private function seniorsOnly(person:*, index:int,
 arr:Array):Boolean{
return (person.isSenior == true?true:false);
   }
   
   
   private function init():void{
   
var ac:ArrayCollection = new ArrayCollection([
{id:1, name:bob, sex:m, isSenior:true},
{id:2, name:kathy, sex:f, isSenior:false},
{id:3, name:joe, sex:m, isSenior:false},
{id:4, name:barb, sex:f, isSenior:true},
{id:5, name:pete, sex:m, isSenior:true}
]);
   
   
var seniors:Array = ac.toArray().filter(seniorsOnly);
   
   
   
   
   
   
   
--- In flexcoders@yahoogroups.com, turbo_vb TimHoff@ wrote:
   
Could use a filterFunction.
   
-TH
   
--- In flexcoders@yahoogroups.com, coder3 rrhuang@ wrote:


 Hi All,

 I have a ArrayCollection, it contains id, name, sex,
   isSenior,
etc.
 now i only need an array of id through that list. what's the
   quickest
way
 to get an array of ids if isSenior is true, without using
 a
   loop?

 thanks

 C

 --
 View this message in context:
   
  
 http://old.nabble.com/how-to-get-an-array-as-a-part-from-another-array--\
 tp26519700p26519700.html
 Sent from the FlexCoders mailing list archive at Nabble.com.

   
   
   
   
   
  
   --
   View this message in context:
  
 http://old.nabble.com/how-to-get-an-array-as-a-part-from-another-array--\
 tp26519700p26521572.html
   Sent from the FlexCoders mailing list archive at Nabble.com.
  
  
  
  
  
 
  --
  View this message in context:
 http://old.nabble.com/how-to-get-an-array-as-a-part-from-another-array--\
 tp26519700p26521778.html
  Sent from the FlexCoders mailing list archive at Nabble.com.