Cartesian product of two or more lists: Difference between revisions
Content added Content deleted
(→Functional JS: Reformulated in terms of Array.flatMap) |
|||
Line 1,092:
For the Cartesian product of just two lists:
<lang JavaScript>(() => {
// CARTESIAN PRODUCT OF TWO LISTS -----------------------------------------
// cartProd :: [a] -> [b] -> [[a, b]]
const cartProd =
// TEST -------------------------------------------------------------------
return
cartProd([1, 2]
cartProd([3, 4]
cartProd([1, 2]
cartProd([]
].map(JSON.stringify).join('\n');
})();</lang>
{{Out}}
|