function nextCartesianIndex( shape, order, idx, dim, out ) {
	var ndims = shape.length;
	if ( ndims === 0 ) {
		return null;
	}
	if ( dim < 0 ) {
		dim += ndims;
		if ( dim < 0 ) {
			// Out-of-bounds:
			return null;
		}
	} else if ( dim >= ndims ) {
		// Out-of-bounds:
		return null;
	}
	if ( order === ROW_MAJOR ) {
		return rowmajor( ndims, shape, idx, dim, out );
	}
	// order === 'column-major'
	return columnmajor( ndims, shape, idx, dim, out );
}
Returns the next Cartesian index (i.e., set of subscripts/dimension indices) and assigns results to a provided output array.

## Notes

-   The function does not check whether the current index is the "last" index. Instead, if the function is provided dimension indices corresponding to the last element, the function will cycle back to the "first" index.

@param {NonNegativeIntegerArray} shape - array shape
@param {string} order - index iteration order
@param {NonNegativeIntegerArray} idx - current dimension indices
@param {integer} dim - index of the dimension from which to start incrementing (inclusive)
@param {(Array|TypedArray|Object)} out - output array
@returns {(Array|TypedArray|Object|null)} output array (or null)

@example
var shape = [ 12 ];
var idx = nextCartesianIndex( shape, 'row-major', [ 2 ], 0, [ 0 ] );
// returns [ 3 ]

@example
var shape = [ 2, 2, 2 ];

var out = [ 0, 0, 0 ];
var idx = nextCartesianIndex( shape, 'row-major', [ 0, 0, 1 ], -1, out );
// returns [ 0, 1, 0 ]

idx = nextCartesianIndex( shape, 'row-major', idx, -1, out );
// returns [ 0, 1, 1 ]

idx = nextCartesianIndex( shape, 'row-major', idx, -1, out );
// returns [ 1, 0, 0 ]

idx = nextCartesianIndex( shape, 'row-major', idx, -1, out );
// returns [ 1, 0, 1 ]

idx = nextCartesianIndex( shape, 'row-major', idx, -1, out );
// returns [ 1, 1, 0 ]

idx = nextCartesianIndex( shape, 'row-major', idx, -1, out );
// returns [ 1, 1, 1 ]

@example
var shape = [];
var idx = nextCartesianIndex( shape, 'row-major', [], 0, [] );
// returns null

@example
var shape = [ 12 ];
var idx = nextCartesianIndex( shape, 'row-major', [ 2 ], -10, [ 0 ] );
// returns null

@example
var shape = [ 12 ];
var idx = nextCartesianIndex( shape, 'column-major', [ 2 ], 10, [ 0 ] );
// returns null