Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8729177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:47:16+00:00 2026-06-13T08:47:16+00:00

I am trying to sort an array and find which one is bigger. So

  • 0

I am trying to sort an array and find which one is bigger.
So I have the original array (CurMobRM), an array with the same values but sorted and reversed (Ary) and finaly an array that has the position of the values of the original array (checking).

A quick example is that lets say the original has the values (3,8,5,2,7) and we sort them so we have an array with the same values but in differnt position (8,7,5,3,2) and the final array that have the original position of every value (3,0,2,4,1).

var CurMobRM:Array = new Array (3,8,5,2,7);
var checking:Array= new Array;
putattackorder();

function putattackorder() {
    var Ary:Array = CurMobRM;
    var lo:Number;
    Ary.sort ();
    Ary.reverse ();
    trace (Ary)
    for (lo = 0; lo < 5; lo++) {
        for (loop = 0; loop < 5; loop++) {
            if (Ary[lo] == CurMobRM[loop]) {
                checking[lo] = loop
            }
        }
    }
    trace (checking)
    trace (Ary)
    trace (CurMobRM)
}

The problem is that when I sort the Ary it seems that CurMobRM is also sorted the same time… I dont understand why. The trace(checking) always give 0,1,2,3,4

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T08:47:17+00:00Added an answer on June 13, 2026 at 8:47 am

    This happens because in ActionScript 3 array objects are assigned by reference, not by value. To overcome this you can use the slice method with no parameters (slice full array).

    For example, in your code:

    var CurMobRM:Array = new Array (3,8,5,2,7);
    var checking:Array= new Array;
    putattackorder();
    
    function putattackorder()
    {
        //perform a copy by value of array
        var Ary:Array = CurMobRM.slice();
    
        var lo:uint;
        var loop:uint;
    
        Ary.sort();
    
        //not necessary?
        //Ary.reverse();
        //trace (Ary)
    
        for (lo = 0; lo < 5; lo++) {
            for (loop = 0; loop < 5; loop++)
            {
                if (Ary[lo] == CurMobRM[loop])
                {
                    checking[lo] = loop
                }
            }
        }
    
        trace (checking)
        trace (Ary)
        trace (CurMobRM)
    }
    

    The output is:

    3,0,2,4,1

    2,3,5,7,8

    3,8,5,2,7

    Which I believe it is what you are looking for. Hope to help!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

ive been trying to sort an array in desc order but have been having
I am trying to sort array with usort, but it doesn't work, What am
I am trying to sort an array in PHP by date and time which
I am trying to sort an array. I have an array of data, where
I'm struggling with trying to sort an array of dictionaries. My dictionaries have a
I'm trying to sort a multidimensional array by multiple keys, and I have no
Possible Duplicate: Sort multidimensional array by multiple keys I am trying to find some
I was trying a problem on SPOJ ,in which we have to simply find
I am actually trying to solve a problem where I have an array which
Trying to sort this array of objects according to (1) depth and (2) weight,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.