Numeric Sorting Difficulties In Array
Hello
I have this great code, courtesy of silentweed, that counts how often every character appears within a string.
Now I've run into the next problem. I need to sort these infos by the amount. I can imagine where the problem lies, but I just can't figure a way around it. With the example below, I keep getting the order 22 d, 3 f, 4 g, while I should get 3 f, 4 g, 22 d.
Code: var obj:Object = {}; var txtEingabe:String = "ggggfffdddddddddddddddddddddd"; var txtAusgabe:Array = new Array();
for ( var i:Number = 0; i < txtEingabe.length; i++ ) {
var letter:String = txtEingabe.charAt(i);
if (!obj.hasOwnProperty(letter)) obj[letter] = 1; else obj[letter]++; }
//calculate percentage and put results in new Array for(var i in obj){ trace("There are " + obj[i] + " instances of the letter " + i); var percent:Number = Math.floor(( obj[i] / txtEingabe.length ) * 100); var amount:Number = ( obj[i] ); //problem might be here? txtAusgabe.push( { l:[i], a:[amount], p:[percent] } ); }
txtAusgabe.sortOn("a", 16); Anyone has any idea what's going on here?
Thanks a lot!
FlashKit > Flash Help > Flash ActionScript
Posted on: 06-27-2007, 04:54 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Sorting A Numeric Array
How can I sort a numeric array in descending order? I'm currently using MyArray.sort(); but this treats the array elements as strings and not as number
Thanks
Sorting Numeric Array
Hi all - I need to sort my array of numbers in ascending or descending order based on value. I can't figure out how to stop getting 1,100,101,102 etc...
thanks
Sorting Multidimensional Numeric Array In MX
I need some help on how to sort an array with nested arrays of matched numbers: one nested array holds x-coordinates and the other nested array holds y-coordinates. The position of each x,y pair is matched, so if I use a typical numerical sorting function, I succeed only in sorting one array or the other, and I undo the relationship.
I describe my arrays below with example x,y coords, and although I may be heading in the wrong direction, I included the function that I know works to sort either one or the other array:
[as]
mySort = function(a,b) {
return a-b;
}
var x= new Array(12,21,-13,48,33);
var y= new Array(6, -99, 7, -2, -2);
var xy = new Array(x,y)
xy.sort(mySort);
//output: -13,12,21,33,48,6,-99,7,-2,-2;
//(only first nested array of xy sorts, so nested arrays lose their relationship)
I need to output: -13,12,21,33,48,7,6,-99,-2,-2
/[as]
The arrays don't have to be nested. I would be happy to be able to sort the x array and have the y array be sorted by the x array.
SortOn() And Numeric Sorting
Hi there:
I'm using sortOn() to sort me some array items. The first item to sort on is a number (4 digit year), and the second item can be an alphanumeric mix. Example of a (correctly sorted) list (the year is not shown, and sorts correctly anyway):
quote:
myArray({"year","title"});
//e.g.: myArray({"1975","My Secret Freedom No. 1"})
/* a correctly sorted list of the "title":
My Secret Freedom No. 1
My Secret Freedom No. 2
My Secret Freedom No. 3
My Secret Freedom No. 4
My Secret Freedom No. 5
My Secret Freedom No. 6
My Secret Freedom No. 7
My Secret Freedom No. 8
My Secret Freedom No. 9
My Secret Freedom No. 10
My Secret Freedom No. 11
My Secret Freedom No. 12
My Secret Freedom No. 13
My Secret Freedom No. 14
My Secret Freedom No. 15
My Secret Freedom No. 16
My Secret Freedom No. 17
My Secret Freedom No. 18
My Secret Freedom No. 19
My Secret Freedom No. 20
My Secret Freedom No. 21
My Secret Freedom No. 22
*/
Using things like the below give me incorrect sorts, with 10 before 1 and so on.
quote:myArray.sortOn(["year","title"],[Array.NUMERIC|Array.DESCENDING,Array.NUMERIC]);
//or
myArray.sortOn(["year","title"],[Array.NUMERIC|Array.DESCENDING,Array.CASEINSENSITIVE]);
//or
myArray.sortOn(["year","title"],[Array.NUMERIC|Array.DESCENDING,Array.NUMERIC|Array.CASEINSENSITIVE]);
/* returns something like:
My Secret Freedom No. 12
My Secret Freedom No. 2
My Secret Freedom No. 3
My Secret Freedom No. 4
My Secret Freedom No. 5
My Secret Freedom No. 6
My Secret Freedom No. 7
My Secret Freedom No. 8
My Secret Freedom No. 9
My Secret Freedom No. 10
My Secret Freedom No. 11
My Secret Freedom No. 1
My Secret Freedom No. 13
My Secret Freedom No. 14
My Secret Freedom No. 15
My Secret Freedom No. 16
My Secret Freedom No. 17
My Secret Freedom No. 18
My Secret Freedom No. 19
My Secret Freedom No. 20
My Secret Freedom No. 21
My Secret Freedom No. 22
*/
What obvious thing have I missed?
Thanks in advance!
Sorting Numeric Values In Arrays - Question
I've created an array that represents dynamically generated numeric values. My problem is that when I try to sort the array in descending order Flash seems to translate single digit values as double digits. For example, say I have an array of 40, 6, 3, 17...
using myArray.sort();
I get: 17, 3, 40, 6
instead of 3, 6, 17, 40.
Its reading "3" as "30" and "6" as 60 etc.
Any ideas on how I can fix this??
Thanks...
Array Difficulties...please Help
Hi,
I'm drawing a line chart that takes its data from a .txt file, converts that data into arrays, and is supposed to draw a line chart from duplicated movie clips....but doesn't.
OK, converting the data from the .txt file into arrays and duplicating movie clips works dandy - Flash Player can see the arrays and the duplicated movie clips show up exactly as I want them - but the chart doesn't draw out.
I want the script to take a cloned movie clip and to send it to frame X, where X is a value in an array, thus:
for (n=0; n<NavDot.length; n++) {
bnav = "NavDot" add n;
duplicateMovieClip ("NavDot", bnav, n+250);
if (Number(n) == 0) {
// Positions the clip on stage
setProperty (bnav, _x, NavDot._x);
bnav.gotoAndStop(NavPlot[n]);
} else {
//Positions the clip on stage
setProperty (bnav, _x, Number(getProperty(bnav, _x)+Number((n-1)*(getProperty(bnav, _width))));
bnav.gotoAndStop(NavPlot[n]);
}
}
...I also tried
for (j=0; j<NavPlot.length; j++) {
tellTarget ("NavDot" add j) {
gotoAndStop (NavPlot[j]);
}
}
But they don't work. The script has no syntax errors, all the movie clip instances are named correctly on stage, so I can't tell what I'm doing wrong...but it sure don't wanna go to frame (NavPlot[n]). The movie clip is simply a little square, motion tweened over 1000 frames(I've used this before so I know it works), and the value in the array should tell that movie clip where to go, but they all remain in frame 1.
Any clues?
Thanks
Lassi
Array Access Difficulties - Tell Me What I'm Doing Wrong...
Hi,
I'm drawing a line chart that takes its data from a .txt file, converts that data into arrays, and is supposed to draw a line chart from duplicated movie clips....but doesn't.
OK, converting the data from the .txt file into arrays and duplicating movie clips works dandy - Flash Player can see the arrays and the duplicated movie clips show up exactly as I want them - but the chart doesn't draw out.
I want the script to take a cloned movie clip and to send it to frame X, where X is a value in an array, thus:
for (n=0; n<NavDot.length; n++) {
bnav = "NavDot" add n;
duplicateMovieClip ("NavDot", bnav, n+250);
if (Number(n) == 0) {
// Positions the clip on stage
setProperty (bnav, _x, NavDot._x);
bnav.gotoAndStop(NavPlot[n]);
} else {
//Positions the clip on stage
setProperty (bnav, _x, Number(getProperty(bnav, _x)+Number((n-1)*(getProperty(bnav, _width))));
bnav.gotoAndStop(NavPlot[n]);
}
}
...I also tried
for (j=0; j<NavPlot.length; j++) {
tellTarget ("NavDot" add j) {
gotoAndStop (NavPlot[j]);
}
}
But they don't work. The script has no syntax errors, all the movie clip instances are named correctly on stage, so I can't tell what I'm doing wrong...but it sure don't wanna go to frame (NavPlot[n]). The movie clip is simply a little square, motion tweened over 1000 frames(I've used this before so I know it works), and the value in the array should tell that movie clip where to go, but they all remain in frame 1.
Any clues?
Thanks
Lassi
Getting Unique Elements From A Numeric Array
Hi There,
Kind of a newbie question but would appreciate any help - I can't seem to find the answer anywhere....
Suppose I have an array of numbers with repetitions, e.g.
[12,20,34,20,60,12,40,34]
How can I either remove any repetitions or create a new array of only the unique numbers?
e.g.
[12,20,34,60,40]
Thanks!
paris
[F8] Numeric Steppers To Populate Array
Hi. I have this array with values from 1 to 20. I am wanting to use to numeric steppers to populate the array or a different array depending on what values are chosen by the steppers. Stepper on is from 1 to 20 and stepper 2 is from 2 to 20.
code:
var myArray:Array = ["A","B","C","D","E","F","G","H","I" etc...up to 20 elements]
//so if they had chose 2 on the first stepper and 5 on the second stepper.
//The array would contain the values B through E
//Then when they make another choice the array would clear itself and do what //They chose say 4 on first stepper and 7 on second
//The array would now contain D through G etc
//Everytime they choose different number on stepper the array clears itself
//then populates with new values. There are 20 possible values in array
I think myArray above would be used to get the elements of a the new array.
Hope that makes sense.
Thanks
JamesLoacher
SortTemp.sort(Array.NUMERIC);
Im sorting using the following
ex.
myArray[x].which=4;...
myArray.sort("which",Array.NUMERIC);
but 10 is sorted as coming before 2, and I cant stop that. How can I get 10 after 9 ?
thanks
SortOn(Array.NUMERIC) Problem...
Does anyone have a clue about why, when i have an array containing three numbers under 1000 and one number over 1000, ex: (702, 711, 981, 1215) and i then use sortOn("num", Array.NUMERIC)* it then moves 1215 ifront, like this 1215, 702,711 and 981...
This is how the array look like,
ActionScript Code:
([num:702 title:"prob1"],[num:711, title:"prob2"],([num:981, title:"prob3"],([num:1215, title:"prob4"])
Keep in mind that the numbers will variate. And this only happen when one of the numbers is over 1000 and the rest is under 1000, if more than two numbers is over 1000 it sorts fine
Array.NUMERIC Flash Mx 2004 Only?
As the title states, is this feature in flashMX 2004 only, i cant get it to work in flashMX. Ive searched everywhere to find out but havent found anything on it, therefore, I'm asking you lot.
Thanks
Sorting A New Array From An Existing Array (emergency)
Hi
i got an existing array, main[y], which after an equation, will come out with another array.
Code:
if (main[y] === topicList.getValue()){
subTopic = [];
subTopic = fTitle[y]
trace(subTopic)
}
However, i could not sort the subTopic, as it gkeep giving me undefined. Is there any way to sort this subTopic, such that they are in alphabetical orders?
Appreciate any help.
Loading Numeric Array From Text File.
var inc = 0;
move = new Array(100,105,110,115,120);
onEnterFrame = function()
{
inc += 1;
_root.mc1._x = move[inc];
if(inc > 4) {inc = 1};
}
__________________________________________________ _____________
The code above works fine and mc1 moves. But I'm attempting(erm? failing) to load the data in the array from a text file in the same directory as the swf. The code below doesn't work.The text file loads and the string of values and commas look correct in a textfield. But the var's are not getting passed to the array, which remains undefined.
__________________________________________________ _____________
var inc = 0;
var loadDataFromText = new LoadVars();
loadDataFromText.onLoad = function(ok)
{
if(ok)
{
loadedData = loadDataFromText.myData;
move = new Array(loadedData);
}
}
loadDataFromText.load("file.txt");
onEnterFrame = function()
{
_root.mc1._x = move[inc];
inc += 1;
if(inc > 10){inc = 1};
}
_______________________________________
The data in the "file.txt" is formatted like this...
&myData=100,105,110,115,120
Please help. Where am I going wrong?
Sorting A New Array From An Existing Array
Hi
i got an existing array, main[y], which after an equation, will come out with another array.
ActionScript Code:
if (main[y] === topicList.getValue()){
subTopic = [];
subTopic = fTitle[y]
trace(subTopic)
}
However, i could not sort the subTopic, as it keep giving me undefined. Is there any way to sort this subTopic, such that they are in alphabetical orders?
Appreciate any help.
Sorting An Array
hi there a quick problem, not really had much exposure to arrays, Ive got 6 integers, which are times which then are placed into an array, Ive been trying to sort them in numerical order but really dont know how to tackle it am I meant to for and if test them all against each other the result are to be displayed in six text field (1-6).....
any help or direction would be greatly appreciated.
thanx in advance!
---Sorting ARRAY-----
Hey guys,
I have the Array (93,101,109,96,94.7,100.5)
So when I sort it it comes out like:
(100.5, 101, 109, 93, 94.7, 96)
In other words it takes the numbers from 100, sort it, and than it takes from 90.
Is there any way to fix it?
Thanks in advance.
Olga.
Sorting Array?
Hi guys,
I'm trying to make an array and sort it alphabetically, how do I go about doing that? Thanks.
Array Sorting
I'm trying to work out a solution to searching through my xml and separating names out into different lists.
Basically I have a node called name. My problem is I need to separate the names out into arrays like this.
Code:
var A_F:Array = [];
var G_L:Array = [];
var M_R:Array = [];
var S_Z:Array = [];
In my xml load I have the names show up like
[code]
function loadXML(url) {
xmlList = new XML();
xmlList.load(url);
xmlList.onLoad = function(success) {
if (success) {
var rootNode = this.firstChild;
numberOfPioneers = rootNode.childNodes.length;
for (var i = 0; i < numberOfPioneers; i++) {
names.push(rootNode.childNodes[i].childNodes[0].firstChild);
}
trace("names :"+names);
}
};
}
loadXML("photo_list.php");
[code]
The trace("names :"+names);
output like:
Code:
names :Nick Arias,Don Blair,Andy Brizio,Jack Calori,Julian Doty,Jim Nelson,Wally Parks,Robert E. Petersen,Bob and Dick Pierson,Ed Pink,Phil Remington,John Wolf,Alex Xydias
No I need a way to search through the last name and take from var A-F, G-L, M-R, S-Z out and place them in there approperate arrays.
Any help on how I could achive this.
Sorting An Array
I need to sort an array. The array looks like this:
[[2],[a],[1],[d],[3],[e]]
I need the results to look like this
[[1],[d],[2],[a],[3],[e]]
In other words the number value is used to also order the letter value
Thanks
[F8] Help With Sorting Array...
I've set up a gallery that loads a php to pull each image file from a folder and send the result to flash, which then puts them into an array. I have a date portion that is also from php. My problem is in flash, trying to create this array so I can sort by date.
Here is the PHP:
PHP Code:
function returnimages($dirname=".") {
$pattern=".(jpg|jpeg|JPG|JPEG)$";
$files = array();
$curimage=0;
if($handle = opendir($dirname)) {
while(false !== ($file = readdir($handle))){
if(eregi($pattern, $file)){
$filedate=date ("YmdHis", filemtime($file));
echo '{file: "'.$file.'", date: "'.$filedate.'"}'.'.:::.';
$curimage++;
}
}
closedir($handle);
}
return($files);
}
echo "&loadArray=";
returnimages();
And here is the AS:
PHP Code:
_root.folderPath = "Images/Portfolio/";
var imgCount:LoadVars = new LoadVars();
imgCount.onLoad = function(success:Boolean):Void {
if (success) {
var gal_str:String = imgCount.loadArray;
gal_array = gal_str.split(".:::.");
trace(gal_array);
} else {
trace("ERROR");
}
};
imgCount.load("myphp.php",imgCount,"GET");
stop();
I'm trying to get my array where I can use "sortOn" date. Any suggestions?
[CS3] Array Sorting
I have this sequence of numbers to be sorted:
Quote:
432534,5646,69855,234,1023,69855,12366,123,10339,7 780036,9803,22310,
69855,5633,0023,70002,600020...
when i use Array.NUMERIC | Array.DESCENDING, it sorts in this way:
Quote:
9803,7780036,70002,69855,69855,69855,600020,5646,5 6233,432534,234,22310,12366,123...... and so on
What i actually expect it to do is to sort the numbers in the order of its real value. Something like :
Quote:
7780036,600020,432534,70002,69855,69855,69855,2231 0,12366,10339,9803,5646,5633,234,123,0023
Sorting In An Array
I want to sort the elements of my object like so:
tile_mc0, tile_mc1, tile_mc2, tile_mc3, etc...
(like when i initialize them....)
for (i = 0; i < 16; i++)
{
tile_holder.attachMovie("tile_mc", "tile_mc" + i, i);
tiles = tile_holder["tile_mc" + i];
tilesPool.push(tiles);
}
the problem is after removing some elements of the Array and using the sort command :tilesPool.sort();
my array looks like this :
tile_mc0, tile_mc1, tile_mc10, tile_mc11, etc...
How do you sort this movie clips names ???
Sorting An Array (again)
I have a few movie clips on the stage and I have named them var1, var2 etc. What I want to do is to have them in an array and I want it to be sorted by depth. Here´s how I do:
Within a for loop i populate the array(sections) and assign the value(lvl) like this:
Code:
for(i=1;i<=4;i++){
this["var"+i].lvl = this["var"+i].getDepth();
sections.push(this["var"+i]);
}
And then I try to sort the array with:
Code:
sections.sortOn("lvl", Array.NUMERIC);
I trace out the array and get:
-16382
-16374
-16358
-16367
Obviously it´s not sorted... any hints?
Array Sorting
Hey all,
Im creating a game where you travel along a board picking up money and losing money. I was wanting to build a bank statement type thing where it stores each varaible you lost or gained in a ordered list as well as updating the balance.
for example:
balance £2000
won £50
balance £2050
payed credit card £300
balance £1750
anyone an idea of how to do this, im reckoning a sorting array but a bit stuck
Cheers
Sorting An Array
Hey all,
I can't seem to figure out how to sort an array of classes.
What i have is an array of my custom class Person. Person has the property Age. And I have an array of Person instances and I want to sort it by the Age property in a decsending manner.
I read about sortOn and tried
array.sortOn(array.Age, Array.DESENDING | Array.NUMERICAL);
and many other variations but it never worked on the whole array. On an array of 6 instances it would only sort the first 4, and they were Ascending.
So, there must a be a good way of sorting them, i tried a few loop combinations to sort it myself but it's trickier than i thought.
So can anyone please help?
Thanks.
Sorting Array Help
hey guys,
I have three arrays named: grRatio, grAlpha and grColor. They are indexed using movie clips, so grRatio for example is setup like something like this:
grRatio[some_mc]=value;
grRatio[another_mc]=value;
so if I do this:
ActionScript Code:
for (var index in grColor) {
trace(index+" color: "+grColor[index]);
}
for (var index in grAlpha) {
trace(index+" alpha: "+grAlpha[index]);
}
for (var index in grRatio) {
trace(index+" ratio: "+grRatio[index]);
}
This is what what I get in the output window:
Code:
_level0.grad_mc.co_mc3 color: 0x0033CC
_level0.grad_mc.co_mc2 color: 0x66CC99
_level0.grad_mc.co_mc1 color: 0x000000
_level0.grad_mc.co_mc0 color: 0x66FF00
_level0.grad_mc.co_mc3 alpha: 42
_level0.grad_mc.co_mc2 alpha: 82
_level0.grad_mc.co_mc1 alpha: 100
_level0.grad_mc.co_mc0 alpha: 72
_level0.grad_mc.co_mc3 ratio: 96.39
_level0.grad_mc.co_mc2 ratio: 56.61
_level0.grad_mc.co_mc1 ratio: 142.29
_level0.grad_mc.co_mc0 ratio: 195.84
Now what i need to do is take the values from these arrays and create 4 new arrays: "color_arr", "alpha_arr", "ratio_arr" and "movie_arr" and sort them in accending order using the values in the grRatio array.
I know I have to use a couple of for loops, but my tries have not worked so far...help!
Sorting Array
Hi,
I have a problem with sorting my array.
I use an array to load external thumbnails and pictures into my movie.
ActionScript Code:
var img_array = ["tp_01.jpg", "tp_02.jpg", "tp_03.jpg", "tp_04.jpg", "tp_05.jpg", "tp_06.jpg"]
var big_array = ["p01.jpg", "p02.jpg", "p03.jpg", "p04.jpg", "p05.jpg", "p06.jpg"]
I want to sort my thumbnails by number, at this moment when i publish my movie on my system he sort the thumbnails good, however when i publish the movie on my server it has a random order. I think he is loading the thumbnails on KB. I have used the sort function but this doesnt work, i think the sort function wil only work when the images are in the flash movie.
So my question:
How do i sort my external thumbnails in order by number?
Much thx to the person that can help me.
Sorting An Array
Hi
I need to sort and array like this:
[[3],[z],[1a],[f],[2],[k]]
to look like this:
[[1],[f],[2],[k],[3],[z]]
The numbers are used to determine the order of the letters
Thanks
Array Sorting
Hi,
I'm trying to sort an array by sorting in ascending order through a property of the array. For example, here is some pseudocode:
Sort arrayList by (arrayList.idNumber)
Is there a way to do this?
Thanks,
~Oni.
Array Sorting
I can't believe i'm asking a question ! It's been ages.
What i would like to know is how to sort arrays without using the `sort` function. even some psuedo code as to how to code your own sort function would be great.
Thanks - icio.
Sorting An Array
Is there a way to do a sort on one array, and then use the new order created as a result of the sort to sort a corresponding array/s?
say i have
ActionScript Code:
array1:Array = new Array("c", "e", "a", "d", "b");array2:Array = new Array("sfas", "weradfa", "asdf", "etw", "nvbncv");
if i sort array1, how can i make array2 match the new order of array1?
Sorting My Array
here is the deal I am dynamically populating my array with some dates like this:
1928,1930,1942,1945,1951,1963,1965,1966,1969,1979,1980,1980,1980,1980,1980,1990,1990,1990,2000,2000,2000,2000
this is no problem. how can i sort through these dates, i want to look through the array and say if I am on 1951 then the next one is 1963 and the previous one is 1945. really i just want to move to the next or previous item in the array, the names are not necessary as they may change. can anyone get me moving in the right direction for this??
thanks,
-brad
Sorting An Array
I need some help sorting an array. My app has a set of four radom number generators. My goal is to dump the results into an array, and then run a function that sorts the array in descending order. I tried a link to some code cold q.sort I found in the forums here, but I couldn't quite see the value. I performed the q.sort and nothing happened. Maybe I misunderstand sorting. Somebody give me some revelation please.
Sorting Big Array
Hi, I have some problem wich I would like to solve:
I made table in flash, with added functionality to sort table by columns. Now I have a problem - loaded xml data make about 300 records with sub arrays like array[(num, name, country)].
So now I need to sort this array, ofcouse I can use built in array.sort with compare function, as it is now. But I think that there should be some faster way. As far I'v looked over internet found nothing.
Any help would be preciated ....
You can see that table and test the speed of built in sort function here and source data here
Sorting An Array
Hello all,
I am hoping to start on a small project for school tomorrow and would like to know if it is possible to create a simple 'rankings table' in Flash. All of the numbers that I intend to display will be held as variables within the script (Actionscript 2.0) and so I do not need to use PHP or anything like that to access or store data.
If, for example, I had the following data:
Code:
team1Name:String = "Red Team"; team1Score:Number = 20; team2Name:String = "Blue Team"; team2Score:Number = 10; team3Name:String = "Green Team"; team3Score:Number = 30;
Could I adapt this data and put it in the form of a numerically sorted table? (See below)
Green Team __30
Red Team ____20
Blue Team____10
I was planning to do the following: put the data into an array and then sort the array numerically.
However, I am not sure whether this is possible or whether it would be the most effective way to create the table.
Any help wih the coding or advice that people could offer before I begin the project would be appreciated!
Thanks as always for any help,
David
Sorting Seperate Array's
Hello all.
i know how to sort arrays and do lotz of other cool stuff with it
BUT!
i have 2 arrays wich contains the following data
Mark 20
Steve 100
Erik 5
arraynames["mark","steve","erik"]
arraycash[20,100,5]
now here it comes, when i sort the cash array i wonna have the names array sorter in the same way
arraynames["steve","mark","erik"]
arraycash[100,20,5]
(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
Sorting An Array Of Numbers
o man..flash is so annoying sometimes...
here's the deal..i have to sort a list of numbers..say :
temp = new Array (1,25,101,23,52,52,92,4)
everybody knows that is should generally turn out to be :
(1,4,23,25,52,52,92,101) or compeletely reverse depending on the sort right?
now, flash, when i use temp.sort(), it returns :
(101,1,23,25,4,52,52,92)
now isn't that queer?
any body got a solution?
help is GREATLY appreciated!
Array Sorting Question
Hi,
I have an array that I want to sort alphabetically, then have all the ones that have a name starting w/ a - l do a certain thing and then the m - z do something else. Make sense?
I know how to sort it alphabetically, I'm just not sure how to see what letter it starts with.
Thanks.
Specifically Sorting An Array
Hey folks,
Quick question...
I've got an array with several values in it... is there a way I can determine dynamically which value appears the most often in said array? For example:
myArray = new array("2", "4", "1", "7", "6", "4", "2", "3", "2")
As we can see, the value "2" appears the most in the above array... so how can I get Flash to dynamically see it too?
Thanks!
- Thingee
2D Array Sorting? (help Needed)
hello, returning to flash after a looong gap to do a new project. I'm having trouble figuring out how to achieve what i need with arrays.
I'll describe it in terms of a database analogy: what i'd like to do is have a table that holds 2 'fields' for each 'record'. The field would be 'name' (a string) and 'depth' an integer.
What i'd like to then do is sort the records in the table in order of 'depth' (from lowest to highest).
And finally, i'd like to iteratively work through the ordered reords, passing the 'name' and 'depth' values of each record in turn, to a function for processing.
If anyone could provide some sample code i'd be very grateful, this is frying my brain
Sorting Arrays Within An Array
hi there,
I have several values stored in multiple arrays (let's call these 'secondary arrays'). Each 'secondary array' is stored in one cell of another array ('main array'). The structure would look something like this:
Code:
mainArray(secondaryArray(number, textField, textField,...), secondaryArray(number, textField, textField,...), ...)
I was wondering if there was a way to sort the secondary arrays according to one of the values in them (namely the 'number')
Is that possible at all? Any help would be appreciated
Ta
Array Sorting Problems
I'm having a bit problem with an array. I have an array like this:
points = Array(1,5,7,2,15,2,2,3,24);
generated dymically, so it can be anything, numbers from 1-20.
what I need to do is to find out the biggest numbers on this array and somehow to get their keys in this array.
so that the final result would be keys: 8, 4, 2
( points[8], points[4], points[2] )
Did anyone understand my rumblings
Thanks.
Sorting An Array Of Objects
Hi,
I have this array of objects, each element of the array contains 3 properties, (link:String, level:Number, Count:Number). I want to sort my array ascendingly based on the 'level' property. Any idea how to do that?
Best Regards
[F8} Sorting Array Craziness
i need to sort arrays, which are loaded as variables via php.
however why wont this sort correctly? it wont put the 30.056 below 45.105
if i sort ascending, it still is incorrect. is there something im not seeing???
Code:
ranges = new Array();
ranges[0]=45.104;
ranges[1]=4.104;
ranges[2]=30.056;
ranges[3]=0.104;
ranges.sort(Array.DESCENDING);
c = ranges.length-1;
for (i=0; i<=c; i++) {
trace("range - " + ranges[i]);
}
output:
range - 45.104
range - 4.104
range - 30.056
range - 0.104
[MX] Simple (?) Array Sorting
Hi there
I was trying to do what I supposed it would be a simple array sorting, but I don't know what I'm doing wrong.
I have an array with several numerical fields of which I'd like to use three to perform a descending sort. The fields in question are "P", "PF" and "DIF". My intention was to use the "P" field as the main sorting criteria, and if there where two identical values for it, use the "PF" field as a second sorting criteria. Same would apply for the "DIF" value. Here's what I tried:
Code:
matriuClasLLIGA.sortOn( ["P", "PF", "DIF" ] , 18 );
You may see the results here the fields used are those listed in the columns. It doesn't work.
A closer version to my original intention, which sadly (and obviously) doesn't take into account the "PF" and "DIF" values was achieved by using this code
Code:
matriuClasLLIGA.sortOn( "P", 18 );
you may see the results here
Any help would be highly appreciated,
Thanks a lot
Sorting An Array With A Loop
I have an array of 500 items. Each one is a combination of 5 letters. "abcde" , "acdbe" etc. Many repeat themselves. I want to compare each item to the rest and find the unique ones and push them into a new array. So I want an array of one of each pattern. I have been trying to create a loop, or even a nested loop, but I can't seem to get 100% accuracy. Any ideas or help would be appreciated. I should have no more than 120 items if they are all unique. Thanks.
[F8] Sorting Array Numerically
hi guys...i am trying to sort an array numerically (1,2,3,4,etc). My output panel is giving me:
0.jpg,1.jpg,10.jpg,11.jpg,12.jpg,13.jpg,14.jpg,15. jpg,16.jpg,17.jpg,18.jpg,19.jpg,2.jpg,20.jpg,21.jp g,22.jpg,23.jpg,24.jpg,25.jpg,26.jpg,27.jpg,28.jpg ,3.jpg,4.jpg,5.jpg,6.jpg,7.jpg,8.jpg,9.jpg
so, here is the code i am working with:
Code:
function loadImages(xml) {
ims = [];
imRoot = xml.firstChild.childNodes;
for (var i = 0; i<imRoot.length; i++) {
ims.push(imRoot[i].firstChild);
}
ims.sort(Array.NUMERIC)
trace(ims)
}
i have tried moving the sort function in the for loop, before the loop, and a few other things...As well, being that really, my array is a set of strings, i tried ims.sort(Array.DESCENDING)....with that , i get
9.jpg,8.jpg,7.jpg,6.jpg,5.jpg,4.jpg,3.jpg,28.jpg,2 7.jpg,26.jpg,25.jpg,24.jpg,23.jpg,22.jpg,21.jpg,20 .jpg,2.jpg,19.jpg,18.jpg,17.jpg,16.jpg,15.jpg,14.j pg,13.jpg,12.jpg,11.jpg,10.jpg,1.jpg,0.jpg
not seeing what i am missing...can you help? thanks
[F8] Sorting A Multidimensional Array
I have an array thats stores an object;
chatters_arr = new array()
chatter = function(name, age, gender){
this.name = name
this.age = age
this.gender = gender
}
for(i=0;i<chatters.length;i++){
chatters_arr[i] = new chatter(
chatters.attribute.name,
chatters.attribute.age,
chatters.attribute.gender,
)
}
Now each time a chatter enters / leaves the room I will push a new object into the array or remove. Afterwards I want to sort the chatters alphabetically. How do I do this?
I know how to use the array sort, but how do I use it to sort the entire array based on the property of an ojbect stored inside?
Thanks.
|