mbostock/d3 — pull request #2082 by mgold (2014-10-21 23:13:01+00:00)
Title: Add d3.product for arrays

As discussed [on the mailing list](https://groups.google.com/d/msg/d3-js/4epALWqwaOM/Br6tjnpXaZUJ), the (Cartesian) product of two arrays is every way of choosing an element from each. This is useful for grids and [scatterplot matrices](http://bl.ocks.org/mbostock/3213173), from which the implementation is taken. I signed the license agreement to cover the tests. This adds only 134 bytes minified.

Proposed documentation (to be added under [Array.pairs](https://github.com/mbostock/d3/wiki/Arrays#d3_pairs) once released):

````markdown
# d3.product(array1, array2)

Returns an array of all combinations of elements from *array1* and *array2*. Each element is an
object with the following fields: `i` is the index into *array1*, `x` is the element from `array1` at
index `i`, `j` is the index into *array2*, and `y` is the element from *array2* at index `j`. The array is
ordered such that all `i` values are grouped in ascending order, and within each group is each `j`
value in ascending order. The function is useful for creating grids, matrices, and crosstabs.
````