//Cartesian product combinationfunctionDescartes (list) {//Parent top-level index; count Pointer counts varPoint = {}; varresult = []; varPindex =NULL; varTempcount = 0; vartemp = []; //to generate a pointer object from a parameter column for(varIndexinchlist) { if(typeofList[index] = = ' object ') {Point[index]= {' Parent ':p index, ' count ': 0} pindex=index; } } //single-dimensional data structures are returned directly if(Pindex = =NULL) { returnlist; } //dynamically generated Cartesian product while(true) { for(varIndexinchlist) {Tempcount= point[index][' Count ']; Temp.push (List[index][tempcount]); } //Press-in result arrayResult.push (temp); Temp= []; //Check for pointer max problems while(true) { if(point[index][' count ']+1 >=list[index].length) {point[index][' count '] = 0; Pindex= point[index][' Parent ']; if(Pindex = =NULL) { returnresult; } //Assign the parent to check againindex =Pindex; } Else{point[index][' Count ']++; Break; } } }}//The code snippet is from: http://www.sharejs.com/codes/javascript/7013varaa=[1,2,3],bb=[1,2,3],cc=[1,2,3],dd=[1,2,3];varZZ=[AA,BB,CC,DD];//any number of arrays herevarSelectspec = [[' 16G ', ' 64G ', ' 128G '], [' Local tyrants Gold ', ' silver ', ' black ', ' Pink '],[' unicom 3G deposit delivery meal ', ' unicom 4G storage fee delivery ', ' Unicom 2G storage fee delivery '], [' 76 RMB package ', ' 106 RMB package ' , ' 206 RMB package ']]; varresult=Descartes (Selectspec); Console.log (Result);d ocument.write (result);
The Cartesian product of JS implementations-product launches