Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 什么';这是创建具有静态和动态值的数组组合的最佳方法_Javascript_Arrays_Performance_Combinatorics_Code Readability - Fatal编程技术网

Javascript 什么';这是创建具有静态和动态值的数组组合的最佳方法

Javascript 什么';这是创建具有静态和动态值的数组组合的最佳方法,javascript,arrays,performance,combinatorics,code-readability,Javascript,Arrays,Performance,Combinatorics,Code Readability,经过长时间的尝试,我成功地编写了一个脚本来创建数组的所有组合,您可以设置组合的级别 但是,当一些元素保持原位(静态)而周围的其他元素发生变化(动态)时,如何在组合的限制下做出选择 这就是我需要的:输出示例: min "static1", "static2", "static3" // (limited by number of static item if min 3) "static2", "static1", "static3" // if true allow change

经过长时间的尝试,我成功地编写了一个脚本来创建数组的所有组合,您可以设置组合的级别

但是,当一些元素保持原位(静态)而周围的其他元素发生变化(动态)时,如何在组合的限制下做出选择

这就是我需要的:输出示例:

  min
  "static1", "static2", "static3" // (limited by number of static item if min 3) 
  "static2", "static1", "static3" // if true allow change order of main
  (4) min+1
  ["others1", "static1", "static2", "static3"]
  ["static1", "others1", "static2", "static3"]
  ["others1", "static2", "static1", "static3"]
  ...
  ["others1", "static2", "static1", "static3"]  true // iIf true, then you can allow static values to reorder
  ["others1", "static2", "static1", "static3"]  true
  ...
  (7) min+4
  ["other", "static1", "other1", "static2", "other1", "static3", "other1"] 
  ...
  (9) max+6 
  ["other2", "static1", "other1", "static2", "other2", "other1", "static3", "other3", "other1"]
  ...
我意识到很可能我做的每件事都错了。也许有更好的方法可以做到这一点。 我的算法速度很差,经常会显示内存不足、循环太多、可读性差的消息。。。 因此,我要求你们向我展示如何最好地进行这种组合

var static_arr1=['a','b','c','d'];
var static_arr2=['a','b','c','d'];
var combi_arr1=['a','b','c','d'];var p=[];var max=“6”;
变量a=[static_arr1,static_arr2,combi_arr1];//或者变量a=['static_arr1':static_arr1,'static_arr2':static_arr2,'combi_arr1':combi_arr1];如果希望使用多维数组没有问题,请将数组转换为数组数组数组或函数create(){var nam=arguments.name;返回{val:arguments,}
//-------------------------------------计数数组:
对于(窗口中的var键){var ss=key;
if(ss.indexOf(“tic”)>-1{p.push(key);var min=p.length;console.log(min);}}//计算全局静态数组并设置最小组合级别
// =====================================
函数get1DArray(arr){return arr.join().split(,“”;}//if数组多维简单转换为1d-丢失的信息和位置:(+fast,siple,c check:if(this.filter(array.isArray).length>1){}
combine=函数combine(k){var toCombine=get1DArray(this);var last;
// ------------------------------------
函数combi(n,comb){var combs=[];

对于(var x=0,y=comb.length;xIn您的
min+4
min+6
示例,为什么会有重复项?这是我对未来的保留。我想在将来创建一个算法,该算法也可以处理重复项。现在我们可以忽略重复项。