Cartesian product of two or more lists: Difference between revisions
Cartesian product of two or more lists (view source)
Revision as of 10:51, 11 January 2023
, 1 year ago→{{header|JavaScript}}
(→{{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}}==
|