JQuery/JS外掛 排列組合 前端實現
阿新 • • 發佈:2020-12-21
原文: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);