var suallar:Array = new Array();
var i:int;
var cavablar:Array=new Array();
suallar.push(["sual1", "duz1", "sehv11", "sevh12", "sevh13","sevh14"]);
suallar.push(["sual2", "duz2", "sehv21", "sevh22","sevh23","sevh24" ]);
suallar.push(["sual3", "duz3", "sehv31", "sevh32","sevh33","sevh34"]);
suallar.push(["sual4", "duz4", "sehv41", "sevh42","sevh43","sevh44"]);
suallar.push(["sual5", "duz5", "sehv51", "sevh52","sevh53","sevh54"]);
var cavablar_temp:Array = suallar.concat();
for (i=0; i<suallar.length; i++){
cavablar_temp[i].shift();
}
trace (suallar);
for (i=0; i<suallar.length;i++){
var number_array:Array = cavablar_temp[i];
var final_array:Array = [];
var count_selected:int = 5;
for (var u = 0; u < count_selected; u++)
{
if (number_array.length == 0)
{
break;
}
else
{
final_array.push(number_array.splice(Math.floor(Math.random() * number_array.length), 1)[0]);
}
}
cavablar.push(final_array);}
trace(cavablar.join("\n"));
trace (suallar);
答案 0 :(得分:0)
根据Array.splice()文档:
向数组添加元素并从中删除元素。此方法无需复制即可修改数组。
当您在循环中间执行number_array.splice()
时,您正在修改推送到suallar
的原始数组。
查看Array.slice()
,它返回一个新数组而不修改原始数据。