A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: sorting seperate array's

  1. #1
    Join Date
    Jan 2001
    Hello all.

    i know how to sort arrays and do lotz of other cool stuff with it


    i have 2 arrays wich contains the following data

    Mark 20
    Steve 100
    Erik 5


    now here it comes, when i sort the cash array i wonna have the names array sorter in the same way


    (just imagin this with 30 names/cash

    any ideas? workarounds? any help appreciated, i tried a few ways by unshift and push to get them sorted in a diff way but it isn't fullproof

  2. #2
    Senior Member
    Join Date
    Apr 2001

    I have an idea

    You could make an object that has a key property. Call your sort function to sort on one property and return the key value. Insert these keys into a sort array and you will have references to the original object.

    .cash <-*

    The sort function would return a value based on the property you want sorted and return the .key.

    Course, I am giving the concept a flourishing nod.. hehe. I have thought about the problem a little, but not THAT much. I would like to see your clever implementation.

    I did a javascript sort once that had an array of arrays. There were only 100 possible values but that should be an implementation detail and it should still work.

    Array [1..100]
    Array[0] [object][object][object]
    Array[1] empty
    Array[2] [object][object]

    Here we see the outer array is really the index for any possible value within the range of 1 to 100. Lets say your value is 5. SortArray[5].push[object]

    .. Now the SortArray's 5 element (which is an array) contains one more object.

    Does this make sense?

    Im rambling again aren't I? lol

  3. #3
    Join Date
    Jan 2001
    lol, is a bit of rambling to me

    but i have been thinking that way also (using some sort of key array as reference) , just dunno how to work it out excactly.

    anyway thx for youre thoughts about it.
    maybe i got some insiration know

  4. #4
    Senior Member
    Join Date
    Oct 2000
    How about storing them in a single 2D array in the first place. That way the pairs would always stay together:

    var myArray = new Array(["Steve", 100],["Mark",20], ["Erik", 5]);

    then you can just sort the whole myArray.

    You may have a reason for not doing this; just an idea.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width

HTML5 Development Center