Skip to content

mschwieb

blog

  • home
  • snippets
  • design
  • projects

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)
        )
    )

Posted byMarco SchwiebertOctober 29, 2021October 29, 2021Posted insnippetsTags:cartesian, javascript, lodash, typescriptLeave a comment on Compute Cartesian Product in Typescript With Lodash
mschwieb, Create a website or blog at WordPress.com
  • mschwieb
    View site in Reader
    Manage subscriptionsSign upLog in
    Report this content
    Collapse this bar