Ciao a tutti,
ho uno script che produrecombinazioni di 3 numri presi da un certo quantitativo di numericontenuti in un array passati alla funzione.
Non è perfetto maFunziona bene



codice HTML:
<!doctype html>
<html lang="en">
 <head>
  <metacharset="UTF-8">
  <metaname="Generator" content="EditPlus®">
  <meta name="Author"content="">
  <meta name="Keywords"content="">
  <metaname="Description" content="">
  <title>Document</title>
 </head>
 <body>
 <script>
function calc(n,k)
{
	var t=1;
  for(i=0;i<=n.length-k;i++)
   {
	   for(j=i+1;j<=n.length-1;j++)
	   {
      for(x=j+1;x<=n.length-1;x++)
		   {
	 document.write("<h1>"+n[i]+" - "+n[j]+"- "+n[x]+"     >"+t+++"° terno</h1>");
  }
 }
}
}


  var n=newArray("a","b","c","d","e","f","g");
  calc(n,3);
  </script>
 </body>
</html>



Poi ho un secondo scriptche produce invece ambi


codice HTML:
<!doctype html>
<html lang="en">
 <head>
 <title>ambi</title>
 </head>
 <body>
 <script>
function calc(n)
{
var t=1;
  for(i=0;i<=n.length-2;i++)
   {
	   for(j=i+1;j<=n.length-1;j++)
	   {


	 document.write("<h1>"+n[i]+" - "+n[j]+"-      >"+t+++"° ambo</h1>");
 }
}
}
  var lotto=newArray(1,2,3,4,5,6,7,8,9);
  calc(lotto,2);
  </script>
 </body>
</html>



Praticamente sono ugualima il secondo per produrre ambi ha un loop for in meno.
Io vorreifondere le 2 funzioni e vorrei che funzionasse tutto semplicementeaggiungendo nella chiamata un parametro che indichi oltre all'arraydi numeri anche il numero 3 oppure 2 oppure 4 per indicare se voglioun ambo o un terno o altro valore.
Grazie