2 Replies - 1208 Views - Last Post: 26 January 2011 - 06:20 AM

#1 pioSko  Icon User is offline

  • still.dreaming
  • member icon

Reputation: 23
  • View blog
  • Posts: 1,888
  • Joined: 06-June 03

Sort numerical array

Posted 22 March 2005 - 12:36 AM

Description: Function for sorting numeric Arrays.
/* function for sorting numeric Arrays.
   use: arrayName.sort(sortByNumber); */

function sortByNumber(a, b) {
  return (a > b);
}

// Example:

myArray = [22, 1, 8, 3, 15, 100];
myArray.sort();
trace(myArray); // output: 1,100,15,22,3,8

myArray.sort(sortByNumber);
trace(myArray); // output: 1,3,8,15,22,100

Is This A Good Question/Topic? 0
  • +

Replies To: Sort numerical array

#2 spendabuk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 08-December 10

Re: Sort numerical array

Posted 08 December 2010 - 09:44 AM

This is incorrect and misleading. The correct function should read public function sortByNumber(a : int, b : int) : int { return (a - b); } Since, the compare function should, according to the Actionscript help, return the following A negative return value specifies that A appears before B in the sorted sequence. A return value of 0 specifies that A and B have the same sort order. A positive return value specifies that A appears after B in the sorted sequence.
Was This Post Helpful? 0
  • +
  • -

#3 vkpvikash  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 23-January 11

Re: Sort numerical array

Posted 26 January 2011 - 06:20 AM

many thanks @ [email protected]
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1