I have this Vector of Objects and each Object has some properities(date, name, id, etc.).
I want to sort the vector by, lets say, a date. How do I do this? I've seen, that an Array would support sortOn() function, but Vectors don't have it.
Object:
public final class DisciplineEvent {
public var id:Number;
public var name:String;
public var date:Date;}
Thanx for answering.
Let's say you have this vector:
var objects:Vector<ObjectType> = new Vector<ObjectType>();
objects.push(obj1, obj2);
You would sort it with:
var sortingFunction:Function = function(itemA:ObjectType, itemB:ObjectType):Number {
if (itemA.date.valueOf() < itemB.date.valueOf()) return -1; //ITEM A is before ITEM B
else if (itemA.date.valueOf() > itemB.date.valueOf()) return 1; //ITEM A is after ITEM B
else return 0; //ITEM A and ITEM B have same date
}
objects.sort(sortingFunction);
more information can be found here: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Vector.html#sort()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With