function GetDataList(keys){
// 保存生成的组合
let newObj = {};
if (keys.length === 0) {
return newObj;
}
// 基础功能
function queue(arr, size) {
if (size > arr.length) { return; }
var allResult = [];
(function (arr, size, result) {
if (result.length == size) {
allResult.push(result);
} else {
for (var i = 0, len = arr.length; i < len; i++) {
var newArr = [].concat(arr);
var curItem = newArr.splice(i, 1);
arguments.callee(newArr, size, [].concat(result, curItem));
}
}
})(arr, size, []);
return allResult;
}
for (let i=keys.length;i>0;i--) {
let newArr = queue(keys,i);
newObj[i] = newArr;
}
console.log(newObj);
};
GetDataList(['鸡肉','酸奶','排骨']);
image.png
网友评论