Cartesian product of two or more lists: Difference between revisions

(→‎{{header|ALGOL 68}}: Added a unary X operator to calculate the product of a list of lists)
Line 2,165:
</syntaxhighlight>
=={{header|JavaScript}}==
function cartesian(m){
if(!m.length)return[[]];
let tails=cartesian(m.slice(1));
return(m[0].flatMap(h=>tails.map(t=>[h].concat(t))));
}
 
===ES6===
====Functional====
Line 2,445 ⟶ 2,451:
 
[]</pre>
 
=={{header|jq}}==