Skip to main content
May 9, 2014
Question

Comparing Array Element

  • May 9, 2014
  • 7 replies
  • 531 views

I have this array

var MyArray:Array;

var ABCD:Array;

var Blu:Array;

var Red:Array;

var Black:Array;

var Pink:Array;

MyArray = [1,2,3,4,5,6,7,10,11,12];

ABCD = ["A","B","C","D"] // A: 1,2,3,4,5,6,7,10,11,12 B: 1,2,3,4,5,6,7,10,11,12 C: 1,2,3,4,5,6,7,10,11,12 😧 1,2,3,4,5,6,7,10,11,12

Blu = [14,9,10,1,2,3,12,5,6,7];     // = A

Red = [13,9,10,1,2,3,4,5,6,7];      // = B

Black = [8,9,10,1,2,3,4,5,6,7];     // = C

Pink = [8,9,10,1,2,3,11,5,6,7];     // = D

1-.) and want to leave for a trace like this:

1A
2A
3A
4A
5A.... up 12
1B
2B
3B
4B
5B... up 12
1C
2C
3C
4C

5C ...up 12
1D
2D
3D
4D
5D...up 12

2-.) then compare the position of each element is stored in the array, and compare to see which is greater

would read high to low:

1A // Value = 14

1B // Value = 13

7A // Value = 12

7D // Value = 11

3A // Value = 10

3B // Value = 10

3C // Value = 10

3D // Value = 10

2A  // Value = 9

2B // Value = 9

3C // Value = 9

3D // Value = 9

..... ETC...

@

if there is another way to organize arrays please show me the code or improve

Thnks All!

This topic is closed to new replies. Start a new post to keep the conversation going.

7 replies

robdillon
Participating Frequently
May 9, 2014

You don't show what code you are using that is failing for you. I would use something like this:

for(var a in ABCD) {

  for(var b in MyArray) {

  var c:* = MyArray+ABCD;

  trace(c);

  }

}

Thanks for responding! I did not understand very well your code, and my example is somewhat understandable why'll post again as I could solve several problems that I had presented earlier, I read more about arrays, the example will place me is an array of Poker is not the same because it does not look the same objective.

I hope it's a little easier to visualize.

Example:

var Cards:Array;

var CardsValue:Array;

var CardType:Array;

CardType = ["Diamond","Spade","Heart","Club"];

Cards =

[[2,   3,  4,  5,  6,  7,  8,  9, 10, "J", "Q", "K", "AS"], //Diamond

[2,   3,  4,  5,  6,  7,  8,  9, 10, "J", "Q", "K", "AS"], //Spade

[2,   3,  4,  5,  6,  7,  8,  9, 10, "J", "Q", "K", "AS"], //Heart

[2,   3,  4,  5,  6,  7,  8,  9, 10, "J", "Q", "K", "AS"]] //Club

CardsValue =

[[40, 41, 42, 43, 44, 45, 46, 47, 48,  49,  50,  51,   52], //Diamond

[27, 28, 29, 30, 31, 32, 33, 34, 35,  36,  37,  38,   39], //Spade

[14, 15, 16, 17, 18, 19, 20, 21, 22,  23,  24,  25,   26], //Heart

[ 1,  2,  3,  4,  5,  6,  7,  8,  9,  10,  11,  12,   13]] //Club

each element of the array is unique in its comparison to the value of each letter,

I want to achieve is:

right through to compare one for each element of the array CardsValue, and to order it with the method of the bubble and print a trace

//output:

Card: ASS Value: 52 TypeCard: Diamond

Card: K Value: 51 TypeCard: Diamond

Card: Q Value: 50 TypeCard: Diamond

Card: J Value: 49 TypeCard: Diamond

Card: 10 Value: 48 TypeCard: Diamond

Card: 9 Value: 47 TypeCard: Diamond

........

Card:3 Value: 2 TypeCard: Club

Card:2 Value: 1 TypeCard: Club

Finish.


or do you recommend me?

sinious

May 11, 2014

for (var i:Number = 0; i<CardsValue.length-1; i++)

{

  for (var j:Number = 0; j<CardsValue.length-1; j++)

  {

  if(CardsValue[0]>CardsValue[j+1][0])

  {

  aux = CardsValue[j+1];

             CardsValue[j+1] = CardsValue;

             CardsValue = aux;

  }

  }

}

for (var i:Number = 0; i<=CardsValue.length; i++)

{

  trace(CardsValue);

}

.

Scene 1, Layer 'Layer 1', Frame 1, Line 39 1151: A conflict exists with definition i the internal namespace