[thelist] Sorting 2D Array in ColdFusion

Michael Buffington mike@price.com
Thu Nov 30 11:50:09 2000
I know I said that this worked like a charm before, but I overlooked
something.  Seems it's not as charming as I had thought.

Perhaps I don't understand the syntax to StructSort, which by allaire is
defined as:

StructSort(Base [, SortType, SortOrder, PathToSubElement])

Base = the name of the structure
SortType = (I assume) "numeric", "alpha"
SortOrder = (I assume) "desc", "asc"
PathToSubElement = (confusing) I think this needs something like
StructName.Key but I try passing that and get an error - I don't think it's
revelevant to my problem right now anyhow.

Here's my problem:

I can use:

StructSort(structOrder, "Numeric", "DESC");

To come up with the following:

Struct. 11 key's 
NAME VALUE 
1 3893  
10 3897  
11 3896  
2 3902  
3 3898  
4 3894  
5 3895  
6 3901  
7 3899  
8 3900  
9 3892

the four digit numbers are considered strings in my code, are never used in
calculations, etc.  The key name is numeric, and should be sorted
numerically, but is being search alphabetically.  Am I getting the syntax
wrong?

What exactly does "PathToSubElement" mean?

Thanks!

-----Original Message-----
From: Raymond K. Camden [mailto:rcamden@allaire.com]
Sent: Tuesday, November 28, 2000 1:32 PM
To: thelist@lists.evolt.org
Subject: RE: [thelist] Sorting 2D Array in ColdFusion


Why not treat column 1 as a structure?

Ie,

struct["2303"] = 3
struct["..."] = x

Then you can simply use StructSort (new to CF 4.5.1 SP2) to sort the
structure.

=======================================================================
Raymond Camden, Principal Spectra Compliance Engineer for Allaire

Email   : jedimaster@allaire.com
ICQ UIN : 3679482

"My ally is the Force, and a powerful ally it is." - Yoda


> -----Original Message-----
> From: thelist-admin@lists.evolt.org
> [mailto:thelist-admin@lists.evolt.org]On Behalf Of Michael Buffington
> Sent: Tuesday, November 28, 2000 4:25 PM
> To: thelist@lists.evolt.org
> Subject: [thelist] Sorting 2D Array in ColdFusion
>
>
> I need to sort values in a 2D ColdFusion array.
>
> By itself, this is a simple task, but it get's tricky. I'm
> converting a text
> file that looks like this...
>
> 2303,3
> 2390,1
> 2302,2
>
> ...into a 2D array that looks like this:
> col1 col2
> 2303 3
> 2390 1
> 2302 2
>
> My intent is to sort the values to look like this:
> col1 col2
> 2390 1
> 2302 2
> 2303 3
>
> I cannot use ArraySort(myArray[2]) because that will only sort col2.
>
> Any ideas?
>
> I may have to back track a good distance and loosen my dependence on this
> data structure, but I can't think of an alternative just yet.
>
> Michael Buffington
> mike@price.com
> (714) 556-3890 x222
> http://www.price.com
> http://www.michaelbuffington.com
>
> ---------------------------------------
> For unsubscribe and other options, including
> the Tip Harvester and archive of TheList go to:
> http://lists.evolt.org Workers of the Web, evolt !


---------------------------------------
For unsubscribe and other options, including
the Tip Harvester and archive of TheList go to:
http://lists.evolt.org Workers of the Web, evolt !