UNPKG

cartesian-product-multiple-arrays

Version:

Find the cartesian product of multiple arrays.

32 lines (28 loc) 701 B
const { cartesianProduct, cartesianProductGenerator, } = require('../lib/product'); const productAttributes = [ ['SM', 'MD', 'LG'], ['Red', 'Green'], ['Cotton', 'Polyester'], ]; const result = cartesianProductGenerator(...productAttributes); const last = [...result].slice(-1)[0]; console.log(last); /* [ [ 'SM', 'Red', 'Cotton' ], [ 'SM', 'Red', 'Polyester' ], [ 'SM', 'Green', 'Cotton' ], [ 'SM', 'Green', 'Polyester' ], [ 'MD', 'Red', 'Cotton' ], [ 'MD', 'Red', 'Polyester' ], [ 'MD', 'Green', 'Cotton' ], [ 'MD', 'Green', 'Polyester' ], [ 'LG', 'Red', 'Cotton' ], [ 'LG', 'Red', 'Polyester' ], [ 'LG', 'Green', 'Cotton' ], [ 'LG', 'Green', 'Polyester' ] ] */