function flattenBy( x, shape, colexicographic, out, stride, offset, clbk, thisArg ) {
	var ndims = shape.length;
	if ( ndims === 0 ) { // 0-dimensional array
		return out;
	}
	if ( ndims === 1 ) { // 1-dimensional array
		// For 1-dimensional arrays, we can perform simple iteration:
		copyBy( x, shape[ 0 ], out, stride, offset, clbk, thisArg );
		return out;
	}
	if ( colexicographic ) {
		flattenColexicographic( x, ndims, shape, out, stride, offset, clbk, thisArg );
		return out;
	}
	recurseLexicographic( x, x, ndims, shape, 0, [], out, stride, offset, clbk, thisArg );
	return out;
}
Flattens an n-dimensional nested array according to a callback function and assigns elements to a provided output array.

## Notes

-   The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).

@param {Array} x - input nested array
@param {NonNegativeIntegerArray} shape - array shape
@param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order
@param {Collection} out - output array
@param {integer} stride - output array stride
@param {NonNegativeInteger} offset - output array index offset
@param {Function} clbk - callback function
@param {*} [thisArg] - callback execution context
@returns {Collection} output array

@example
var Float64Array = require( '@stdlib/array/float64' );

function scale( v ) {
    return v * 2;
}

var x = [ [ 1, 2 ], [ 3, 4 ] ];

var out = flattenBy( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale );
// returns <Float64Array>[ 2, 4, 6, 8 ]

@example
var Float64Array = require( '@stdlib/array/float64' );

function scale( v ) {
    return v * 2;
}

var x = [ [ 1, 2 ], [ 3, 4 ] ];

var out = flattenBy( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale );
// returns <Float64Array>[ 2, 6, 4, 8 ]