-2
我有兩個不同的陣列,setOne
和setTwo
。我想創建一個包含10個元素的新數組,但前3個元素應該從第一個數組(setOne
)隨機選取,其餘7個將來自setOne
和setTwo
。如何使用從第一個和第二個數組中獲取n值創建新陣列
這裏是數組:
var setOne = [['12+16','28'], ['15+11','26'], ['16+22','38'], ['13+14','27'], ['15+24','39'], ['14+12','26'], ['10+17','27'], ['11+11','22'],
['13+15','28'], ['12+21','33'], ['24+13','37'], ['33+21','54'], ['40+18','58'], ['34+31','65'], ['25+42','67'], ['22+15','37'],
['24+12','36'], ['20+15','35'], ['25+14','39'], ['21+21','42'], ['41+25','66'], ['53+24','77'], ['35+31','66'], ['62+37','99'],
['54+35','89']];
var setTwo = [['15+18=','33'], ['17+17=','34'], ['13+19=','32'], ['18+14=','32'], ['15+27=','42'], ['18+17=','35'], ['27+29=','56'], ['23+28=','51'],
['36+37=','73'], ['45+25=','70'], ['46+45=','91'], ['38+57=','95'], ['49+43=','92'], ['37+53=','90'], ['48+33=','81']];
generateQues: function() {
//Set position for set Questins
//quesTextValue = this.add.text(50,400,randQues[0], textStyleQues);
// Generating random questions from given list of ques - setOne.
for(var i = 0; i < 3; i++) {
if(i<=3) {
var ranNum = Math.floor(Math.random() * setOne.length);
//console.log(ranNum);
randQues = setOne[ranNum];
console.log(randQues);
// quesTextValue = this.add.text(50,400, randQues[0],textStyleQues);
} else {
var ranNum = Math.floor(Math.random() * setTwo.length);
var rque = setTwo[ranNum];
console.log(rque);
randQues.push(rque);
console.log(randQues);
}
}
// quesTextValue.destroy();
},
請幫我解決這個問題。
沒有按照預期的代碼無法正常工作,您可以在這裏貼了嗎? – zee
是的,我在編輯問題。 –