An array of Programming basics cross Merge

Source: Internet
Author: User

Keep on talking about yesterday. Today's content is relatively simple, arrays are interleaved. The problem is as follows

Write a function that interleaved merge list elements. For example: The given two lists are [a,b,c] and [three-to-one], and the function returns [a,1,b,2,c,3].

The code refers to the following program. Test screen


Get the contents of two arrays var arrdata = new Array (); arrdata[0] = document.getElementById ("Q2i1"). Value.split (","); arrdata[1] = document.getElementById ("Q2i2"). Value.split (",");//Find the largest array of superscript var intmaxlength = (Arrdata[0].length > arrdata[1]. Length)? Arrdata[0].length        : arrdata[1].length//declaration result Array and counter var arrresult = new Array () var intrstidx = 0;//follow superscript maximum array loop for (Var i = 0; i < intmaxlength; i++) {    //two array loops to be interleaved for    (var j = 0; J < Arrdata.length; J + +) {        //) If the array has values, stagger merge if        (ARRDATA[J].L Ength > i) {            arrresult[intrstidx] = arrdata[j][i];            intrstidx++; This is the most easily forgotten line of code for novice Programmers        }    }}document.getelementbyid ("q2a"). Value = Arrresult.join (",");


An array of Programming basics cross Merge

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.