JQuery/JS插件 排列组合 前端实现

原文:https://www.cnblogs.com/kissdodog/p/5419981.html

这里就只改造了组合


        // 原文:https://www.cnblogs.com/kissdodog/p/5419981.html
        var GetCombination2 = function(list, t, n, m, b, M)
        {
            for (var i = n; i >= m; i--) {
                b[m - 1] = i - 1;
                if (m > 1) {
                    GetCombination2(list, t, i - 1, m - 1, b, M);
                }
                else {
                    if (list == null) {
                        list = [];
                    }
                    var temp = [];
                    for (var j = 0; j < b.length; j++) {
                        temp[j] = t[b[j]];
                    }
                    list.push(temp);
                }
            }
        }

        var GetCombination1 =function (t, n)
        {
            if (t.Length < n)
            {
                return null;
            }
            var temp = [];
            var list = [];
            GetCombination2(list, t, t.length, n, temp, n);
            return list;
        }

        var ListCombination = GetCombination1(["gu", "xing", "yue"], 2); //求全部的3-3组合
        console.log(ListCombination);


原文地址:https://www.cnblogs.com/guxingy/p/14168565.html