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