Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 04-29-2009, 07:13 PM   #1
iomega_zippy
Registered User
 
Join Date: Oct 2005
Posts: 3
Default Javascript version of AS2's Array.sortOn() method

I have an array of objects and I'm looking for a Javascript prototype (or something) that will work as nicely as AS2's Array.sortOn() method, namely being able to pass it an array of object keys to sort and sub sort on, and a matching array of type of sort (ascending, descending, numeric, or a combo of those).

Current use in AS2 functionality test:

Code:
var totalArr:Array = [];

function addEntry(rating:Number, importance:Number) {
	totalArr.push({competency: competencyNum, total: (11 - rating) * importance, rating: rating , importance: importance});
	totalArr.sortOn(["total", "rating", "importance"], [Array.NUMERIC|Array.DESCENDING, Array.NUMERIC, Array.NUMERIC|Array.DESCENDING]);
}
iomega_zippy is offline   Reply With Quote
Old 04-29-2009, 07:14 PM   #2
iomega_zippy
Registered User
 
Join Date: Oct 2005
Posts: 3
Default Javascript version of AS2's Array.sortOn() method

I have an array of objects and I'm looking for a Javascript prototype (or something) that will work as nicely as AS2's Array.sortOn() method, namely being able to pass it an array of object keys to sort and sub sort on, and a matching array of type of sort (ascending, descending, numeric, or a combo of those).

Current use in AS2 functionality test:

Code:
var totalArr:Array = [];

function addEntry(rating:Number, importance:Number) {
	totalArr.push({competency: competencyNum, total: (11 - rating) * importance, rating: rating , importance: importance});
	totalArr.sortOn(["total", "rating", "importance"], [Array.NUMERIC|Array.DESCENDING, Array.NUMERIC, Array.NUMERIC|Array.DESCENDING]);
}
iomega_zippy is offline   Reply With Quote
Old 04-29-2009, 07:35 PM   #3
Xegnma
Member
 
Join Date: Sep 2007
Posts: 84
Default

Javascript arrays do have a sort function, but its not equivalent to ActionScripts Array.sortOn() method. For that you will have to write custom code to pull it off.
Xegnma is offline   Reply With Quote
Old 04-29-2009, 09:52 PM   #4
yell0wdart
jordanrift.com
 
Join Date: Sep 2007
Location: Phoenix, AZ
Posts: 366
Default

Yep. Any custom sorting would need to be added to the Array prototype at runtime.
__________________

bad developer

Jordan Rift
yell0wdart is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Detecting standalone player version from projector. MrMayhem ActionScript 2.0 3 05-09-2005 01:01 PM
Database simulated with arrays on a cd-rom lecasn5 Components 61 09-07-2004 11:40 AM
inheritance - Mortimer Jazz ActionScript 1.0 (and below) 10 07-24-2003 09:51 PM
detecting the flash player version Mathieu_BSL ActionScript 1.0 (and below) 0 10-22-2002 07:12 PM
Php, Javascript, and Flash 5 browser detect and more! Redline01 Server-Side Scripting 2 08-11-2001 01:09 AM


All times are GMT. The time now is 04:36 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.