คำอธิบาย
เขียนฟังก์ชันหาการจัดหมู่ (combinations) ของสมาชิกในอาร์เรย์
ตัวอย่างโค้ด
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);
วิธีรัน
node fileName.js
ผลลัพธ์
[ '44', '45', '54', '55' ]