Compute Cartesian Product in Typescript With Lodash

import * as _ from "lodash";

const getCartesianProduct = (
    m: number[][],
    n: number[][]
): number[][] =>
     _.flatMap(m, mRow =>
        _.map(n, nRow =>
            mRow.concat(nRow)
        )
    )

Leave a comment