1 //Combination2 functionGenerategroup (arr) {3 //initializes the result to the first array4 varresult= arr[0];5 //traversing a two-dimensional array starting from subscript 16 for(vari=1;i<arr.length;i++){7 //use a temporary traversal to replace the result array length (this is done to avoid looping the following loop into a dead loop)8 varSize=result.length;9 //depending on the length of the resulting array, the number of members of the array will be combined with the next array how many timesTen for(varj=0;j<size;j++){ One //iterating over the array to be combined A for(vark=0;k<arr[i].length;k++){ - //Put the combined string into the last member of the result array - //The subscript 0 is used here because it is useless when the subscript 0 is combined, and we are going to remove the member below. theResult.push (result[0]+ "," +arr[i][k]); - } - //when the first member group is complete, delete this first member - Result.shift (); + } - } + //Print Results A Console.log (result); at } - -Generategroup ([["Red", "Blue"],["X", "XL"],["10m", "20m"]]);
Product Release specification combination this has been my headache, after all, is the first contact with e-commerce project development, the company did not lead, the project development members of a total of 4 people, two front-end two back end, the product release this piece relative to other pages more trouble, so the product release front end are I contracted.
Our project development team, looks more like a research and development team, do not know anything, everything is blind. Hey, it's sad to say more
Here's my idea:
At the beginning, a variable result is created and the first array member of ARR (Arr is a two-dimensional array) is assigned to it and then the result is combined with the following array member, always with the result No. 0 member going and the target combination, When the combination is determined to no longer be used, remove the subscript 0 member, so that the final result will only retain the useful data, here is a bit like a queue, FIFO meaning.
For example:
There is data: {a,b}{c,d}{e,f,g}
Initialize: Result={a,b}
The first combination gets: A_c,a_d The result is {a,b,a_c,a_d} after the end of this round combination, after deleting a, result is {b,a_c,a_d}, next round.
Nth time combination in turn ...
This is my idea, perhaps there is a better way, but this is my head to break out of the method, if you have a better way, please recommend to me, thank you.
[e-commerce] product release specification combination algorithm