Bạn có thể tự viết hàm để lấy tất cả các tổ hợp.
Ví dụ
Mã thực hiện:
function combination(values) {
function * combinationRepeat(size, v) {
if (size)
for (var chr of values)
yield * combinationRepeat(size - 1, v + chr);
else yield v;
}
return [...combinationRepeat(values.length, "")];
}
var output = combination([4,5]);
console.log(output);
Để chạy chương trình, sử dụng lệnh:
node fileName.js.
Tên file của tôi là demo306.js.
Kết quả
Đầu ra:
PS C:\Users\Amit\javascript-code> node demo306.js [ '44', '45', '54', '55' ]