HUH函数
function group(total, size) { var groupList = [] var arr = [] for (let i = 0; i < total; i++) { arr.push(i + 1) } (function (arr, size, group) { var arrLen = arr.length if (size > arrLen) return if (size == arrLen) { groupList.push([].concat(group, arr)) } else { for (var i = 0; i < arrLen; i++) { var newGroup = [].concat(group) newGroup.push(arr[i]) if (size == 1) { groupList.push(newGroup) } else { var newArr = [].concat(arr) newArr.splice(0, i + 1) arguments.callee(newArr, size - 1, newGroup) } } } })(arr, size, []); return groupList;}console.log(group(3, 2))console.log(group(4, 2))console.log(group(4, 3))console.log(group(5, 2))