I was trying to determine a way to sort an array without all the for loops and that sort of business when I ran across this post
Granted it’s a little specific to what you want to sort but I’m sure with a little change you could sort based on the function call maybe. I implemented it for my map stuff and it worked out great for plucking out regions that items are on.
private function makeRegionList(myMapItemsArr:Array = null):Array {
var tempArr:Array = myMapItemsArr;
var keys:Object = {};
var tempArr2:Array = tempArr.filter(function(item:Object, idx:uint, arr:Array):Boolean {
if (keys.hasOwnProperty(item.regionCode)) {
/* If the keys Object already has this property, return false and discard this item. */
return false;
} else {
/* Else the keys Object does *NOT* already have this key, so add this item to the new data provider. */
keys[item.regionCode] = item;
return true;
}
})
return tempArr2
}
Leave a Reply
You must be logged in to post a comment.