array sort in flash
- Started
- Last post
- 42 Responses
- JamesEngage
Hello,
lets says I have an array of numbers e.g myArray=[12,87,32]
Anyone know of a function that will create a new array that reports the order in which they exist?
e.g would return:
orderOfArray= [0,2,1]
- ozhanlion0
what kind of order is that?
I mean howdy get 0 for 0 and 2 for 1 and 1 for 2?
- j_red0
Array.sortOn()
- JamesEngage0
it is say that it is saying position 0 is the lowest and then position 2 and then position 1
- ozhanlion0
erm I got it now. maybe you can do something like storing the array element numbers within those elements myArr[i].nmbr
and then sort this array according to yourneeds and extract another array with the nmbr property again,
no ?
- j_red0
jamesEngage, ozhanlion check your emails, i sent it to you.
- JamesEngage0
hmm that returns the array without doing anything to it?
- jkosoy0
I'd like to see how this one pans out. I can think of a solution off the top of my head for this sort of thing...but it involves comparing each number to the ones prior to it and sorting that way. Which sounds like it could get pretty processor intensive pretty quickly.
- JamesEngage0
Hmm that it what I'm trying to do at the mo... it gives me a result.. but slightly wrong!
- jkosoy0
Can I see what you've got James? Maybe another brain to pick at it could help...?
- j_red0
apologies jame, i thought you wanted to sort them by value - i'll look at it some more.
- JamesEngage0
'sorted' it... will post it up in a sec... bit dirty though I imagine!
- JamesEngage0
function reportOrder(myArray) {
for (n=1; n
- JamesEngage0
grr
- JamesEngage0
function reportOrder(myArray) {
for (n=1; n
- instantok0
i wanna see!
hi jamie...
- JamesEngage0
it's James... I'm not a fecking CHAV!
- jkosoy0
ha. hi justin.
- JamesEngage0
oops!
- instantok0
haha...sorry i was actually saying hi to jkosoy (j for jamie)
thanks for the sort jumpoff
- jkosoy0
Not bad James. Only thing I don't like is the limitation between the numbers. Obviously easy to adjust but it'd be nice to make it uber universal.
I'll tinker with it when I'm a little less busy and see if I come up with anything.
Nice job.