SOURCE

function combine(arr, size) {
    let arrResult = [];
    (function(arr, size, result) {
        let arrlen = arr.length;
        if (size > arrlen) return;
        if (arrlen === size) {
            arrResult.push([].concat(result, arr));
        } else {
            for (let i = 0; i < arrlen; i++) {
                let newResult = [].concat(result);
                newResult.push(arr[i]);
                if (size === 1) {
                    arrResult.push(newResult);
                } else {
                    let newArr = [].concat(arr);
                    newArr.splice(0, i + 1);
                    arguments.callee(newArr, size - 1, newResult);
                }
            }
        }
    })(arr, size, [])
    
    return arrResult;
}

console.log(combine([1,2,3,4,5], 3));
console 命令行工具 X clear

                    
>
console