JSFiddle - React, Tailwind, and code Playground
by lid0
HTML
check console.log combinations
JavaScript
// source questions/165664/cartesian-product-of-a-list-with-itself-n-times
//f=c=>g=(n,...l)=>n?c.map(w=>g(n-1,...l,w)):console.log(...l)
// simplified/expanded, and changed to return instead of printing.
function combinations(c){
var x = [];
return function g (n,...l){
if(n==0){ x.push(l); return }
c.map(w=>g(n-1,...l,w))
return x
}
}
var z = combinations(['a','b','c'])(2)
console.log("all combinations",z)