Sorting algorithm: How can I sort both arrays according to a

I have two rows parallel, similar to this:

var array1 = [4, 3, 1, 5, 2];

var Array2 is ['four', 'three', 'one', 'two', 'five'];.

I want to sort the first table and the second table followed the same kind as the first. Any advice for a good algorithm would be appreciated.

Rick Quatro

This gives a try!

var array1 = [4, 3, 1, 5, 2];
var array2 = ["four", "three", "one", "five", "two"];

bubbleSort(array1,array2);

function bubbleSort(a,b)
{
    var swapped;
    do {
        swapped = false;
        for (var i=0; i < a.length-1; i++) {
            if (a[i] > a[i+1])
            {
                var temp = a[i];
                a[i] = a[i+1];
                a[i+1] = temp;

                var temp = b[i];
                b[i] = b[i+1];
                b[i+1] = temp;
                swapped = true;
            }
        }
    } while (swapped);
}

alert(array1);
alert(array2);

Tags: InDesign

Similar Questions

  • Recently, when I try to retrieve my e-mail with windows mail, he asks me my login and password. I do not remember to be! How can I reset both?

    Recently, when I try to retrieve my e-mail with windows mail, he asks me my login and password. I do not remember to be!  How can I reset both?

    Hello

    Contact your ISP (Internet Service Provider) if they provided you with your e-mail account

  • Sort both arrays

    Hi all

    If we are given two berries sorting, X and Y and X has a big enough buffer at the end of stay there.

    How can merge us Y X in a sorted order.

    X = (1,4,7,8)

    Y = (2,5,6)

    output: 1,2,4,5,6,7,8

    Thank you

    Rambeau

    This is a table... so a table is a construction that has a number of elements.

    The presentation of an array is can be done like this:

    SELECT listagg (COLUMN_VALUE, ',') WITHIN GROUP (ORDER BY COLUMN_VALUE)

    IN my_string

    table (z);

    sys.dbms_output.put_line (my_string);

    HTH

  • The "Show bookmarks" icon disappears when the display of the menu bar. How can I see both?

    Accidentally, I dragged my mouse over the link to bookmarks on the right part of the bookmarks toolbar, and he disappeared. I restarted the browser in safe mode and bookmark link was back, but the menu bar was not visible. When I do the menus visible bar, the bookmarks link disappears again, even if the rest of the bookmarks are visible. How can I get the favorite link so the bar menus visible at the same time?

    Right-click on an empty space on a toolbar, and you will get the Customize option. You will get a pane with icons that can be dragged the toolbar. The tabs list icon is the one I think you have dragged. You can also use the reset option [restore default set]

  • How can I get my array of Images to take you want available?

    I am creating a web page as part of my learning of html and css, it's a page of bookmarks with the sites I visit most often. The main section of the page is a table of images that are related to their respective sites, the table is of 4 columns of 3 rows. My problem is when in the design window, it appears as it should, but when I press the live button and when I saw in a browser it all the images are in a column on the left side of the page. How can I fix this?

    Any help is greatly appreciated.web page help2.pngWeb page help1.png

    Thank you.

    The tables are a bad choice in Responsive Web Design.  Best option, use CSS floats.

    Add this to your CSS:

    .myIcons {

    overflow: hidden; / * float containment * /.

    }

    IMG {}

    Padding: 2%;

    margin: 0.50%.  / * the space between images * /.

    float: left;

    border: 1px solid #CCC;

    Max-width: 100%;

    vertical-align: baseline;

    }

    Replace your table with this:

    http://www.Google.com">".

    http://www.BBC.co.UK' > '.

    http://www.codeacademy.com">."

    http://www.NBA.com' > '.

    http://www.Facebook.com"> http://www.espn.com" > "

    http://www.Twitter.com' > '.

    http://www.celticfc.NET/mainindex">."

    http://www.YouTube.com' > '.

    http://www.collegehumour.com">."

    http://www.skysports.com' > '.

    http://www.nbcnews.com/ID/3032619/">."

    Nancy O.

  • Nagle algorithm, how can I fully disable it?

    Greetings...

    I am a world of warcraft player trial current release candidate of windows 7. In windows vista, we were able to use the patch KB935458v2 and added the TcpAckFenquency 32-bit Dword value more the TCP_NoDelay dword 32 bit key and it allowed me to play 600 Ms 95 to 130ms, right now, only the key TCPAckfrequency works but it is impossible to turn off the nagle algorithm, can someone show me how to disable in windows 7?

    Hello Uzume,

    Please use the Forums for Microsoft Windows.

    Sorry, you experience this problem.  I suggest you post your question on the link below for the Windows 7 Forums.  You can search FAQ so that present.  This forum is no longer on the compatibility issues and installation.  Thank you!

    Windows 7
    http://social.technet.microsoft.com/Forums/en/category/w7itpro, windowsvistaitpro, windowsxpitpro / Engineer James Microsoft Support answers visit our Microsoft answers feedback Forum and let us know what you think.

  • How can I create multidimensional arrays of controls?

    I build a VI that will have hundreds of power keys, 24 on each of the 8 tabs.  I can deal with them programmatically in an array, like this:

    and to find one that was pushed with some XOR'ing:

    But what happens if I want two rows of 12 buttons?  I can make a 2D buttons somehow?  Or a table 1 d of buttons on two lines for aesthetic reasons?

    What happens if I want to put 24 buttons on each of the 8 tabs?  Can I make a table of 24 x 8 controls somehow?  Or a 2 x 12 x 8?

    Thank you

    -Jordan

    Right click on the display of the Index and Add Dimension.

    I would be cautious to put too many buttons. Makes for an awkward interface.

  • How can I pass an array to an another vi without using the Subvi

    Hi all

    Is there a way to pass a 1 d table go a VI to another without using the Subvi?

    Mmehrabin wrote:

    I need to store data of FPGA. I can write them to a file on FPGA or should I transfer to the host VI and then store them in a file?

    The FPGA has no access to a disk.  You will need to pass data to the host (preferably with a FIFO DMA) and then the host can save data to a file.

  • How can a VI both server and client?

    Hello

    I'm new in LabView and I am trying to build a VI client and server using the TCP/IP protocol that runs in both computers. in my program I need of server and client screws to communicate with each other which means that I need the two screws to be server and client. I tried using a case structure, but it does not work. The only thing I have achieved is a normal client/server system, where the server sends a query and the customer responses. But I need the client to send requests too.i have attached my screws to this post. I would appriciate it if someone could help with this problem.

    Thanks in advance.

    Rambaldi.

    Rambaldi wrote:

    OK, im kind of confused.i came with these attached screws that do not work and its embarrassing.would would it be possible that draw you a sketch or a sample?

    You have cases in the case of inverted structure. The second reading is scheduled in the case by default. Currently, you read only if the size is 1, which never happens.

    In addition, the client should probably change the order of operations. He should write first, and then read them.

    End of the loop is always so true, that seems backwards, especially if pair you it with a button labeled "stop."

  • How can I define my array to display in excel csv correctly?

    I currently have an array of 6 elements of type double entries. I am using writing worksheet function to produce this table in a csv file. Since it seems that the table has no space at the exit to the writing of the worksheet function, the output for each line is as follows:

    0.000.2310.2410.3310.5420.334

    I need it for output in separate columns in the csv as this files:

    0.00 0,231 0,331 0,241 0,542 0,334

    What I am doing wrong?

    As you write in a CSV file, Excel expects a comma as a delimiter.  Then make sure your separator is a comma (the default is a tab).

  • How can I keep both computers synced?

    I have laptop and tower under XP.  Y at - it an easy way, the two are always mirrored images, if a file is modified on a it is changed on the other so I don't have to spend hours to copy the files until I'm going on a long trip or go home!  Same questions for Outlook, but understand best answer is export and import (incorrect).  "MY Breifcase" used to work well, but not here now.  Thank you

    Microsoft SyncToy is a free application that works reasonably well.  If you wait, other people can offer non-Microsoft solutions.

    If you go with SyncToy, know that there is a specific SyncToy forum you use for any questions rather than posting questions in the Microsoft Answers forums

  • How can I use both scrolling and vertical scroll?

    Hello

    I am new to Blackberry. I have drawn on the use of horizontal and vertical scrolling scroll, however there is no adequate solution (or there is really no way?). Furthermore, I'm showing a datagrid on the screen, but it does not fit in the screen. There are twelve columns and more than a hundred lines which are not editable or selectable.

    Thanks for your replies!

    If you override Manager.moveFocus () you can manually call setVerticalScroll() or setHorizontalScroll(). You can use the status of the function moveFocus to say if you move vertically or horizontally.

  • How can I do both screens go away and return to a single?

    SShift-Cmd-7 to close viewing angle

  • I have Flash CC on a macbook pro and I can't put more than two audio files in the same scene. How can I do both play?

    Captura de pantalla 2016-01-22 a las 9.38.51 AM.png

    Access your library window. You should see all the audio files that you have imported into your movie. Choose the one that will play no and set to play in the "library" window There is a small play button at the top right of the preview window when you select the audio file. He plays this window?

    If he does not, he cannot be an able to interpret Flash audio file. Open the properties of this file and tell us what kind of file it is.

  • How can I build an array based on the check boxes "checked"?

    OOP! Just realize that this is in the wrong forum. Sorry

    Hey all the... I just have a question on forms in FLEX 2:

    I have a Repeater that is populated by a list of musicians from a XML file. Each artist is represented by a box and when the user clicks a "submit" button, I want to than this table to be sent to a php script.

    It's the vbox containing the details of the artist and the checkbox:


    < mx:VBox >
    < mx:Text text = "{artistRepeat.currentItem.name}" / > "
    < source = mx:Image
    scaleContent "{artistRepeat.currentItem.image}" = "true" / >



    "< mx:CheckBox data =" {artistRepeat.currentItem.name} "id ="cBox"click =" modifyArray (Object) "/ >
    < mx:Text text = "{cBox.data}" / > "

    < / mx:VBox >


    And the management is:



    public void modifyArray(item:Object):String {}
    If (cBox.data! = null) {}
    Return artistlist.text;

    }
    return artistlist.text = "(artiste =" + cBox.data+ "cBox.data+") "; » ;


    }


    He registered the artist as "undefined". I'll the sense here?

    Thank you
    Tom

    EDIT: Never mind. I got it with this program. We finished.

    This is a user friendly like a speed bump hoof. Honestly, I will never use once I have the degree, unless Adobe stop using the Russians to write their error messages and a decent site somewhere be configured.

    I'm sorry, I feel pretty bad so that a program has almost caused several heart attacks. It is not good for my health this building :-)

    Anyway thanks,
    Tom

Maybe you are looking for