js计算笛卡尔积

一行实现笛卡尔积

[[1,2,3],['A','B','C']].reduce((a, b) => a.flatMap(x => b.map(y => x+y)), [[]])
// ['1A', '1B', '1C', '2A', '2B', '2C', '3A', '3B', '3C']

其他实现

这是很久以前一个群友问的问题,当时是硬逻辑写出来的,仅供参考

猜你喜欢

转载自blog.csdn.net/weixin_43840202/article/details/121222171