Find all combinations of two arrays

前端 未结 5 686
长情又很酷
长情又很酷 2021-02-15 17:02

I am trying to find all the combination of two arrays, but with an important variation:

Each value of the second array needs to be spread out over the val

5条回答
  •  日久生厌
    2021-02-15 17:36

    Just for illustration, this is a version of @NinaScholz's answer that doesn't use toString for base conversion or implement counting manually. I've kept the structure of the code the same. values.length-i-1 could simply be `i', but I wanted to keep the order of the output the same too.

    var combine = function(names, values){
        var result = [],
            max = Math.pow(names.length, values.length),
            m;
        for(m=0; m

提交回复
热议问题