function reshape(array, sizes) {
  var flatArray = flatten(array);
  var newArray;

  function product(arr) {
    return arr.reduce(function (prev, curr) {
      return prev * curr;
    });
  }

  if (!Array.isArray(array) || !Array.isArray(sizes)) {
    throw new TypeError('Array expected');
  }

  if (sizes.length === 0) {
    throw new _error_DimensionError__WEBPACK_IMPORTED_MODULE_2___default.a(0, product(size(array)), '!=');
  }

  var totalSize = 1;

  for (var sizeIndex = 0; sizeIndex < sizes.length; sizeIndex++) {
    totalSize *= sizes[sizeIndex];
  }

  if (flatArray.length !== totalSize) {
    throw new _error_DimensionError__WEBPACK_IMPORTED_MODULE_2___default.a(product(sizes), product(size(array)), '!=');
  }

  try {
    newArray = _reshape(flatArray, sizes);
  } catch (e) {
    if (e instanceof _error_DimensionError__WEBPACK_IMPORTED_MODULE_2___default.a) {
      throw new _error_DimensionError__WEBPACK_IMPORTED_MODULE_2___default.a(product(sizes), product(size(array)), '!=');
    }

    throw e;
  }

  return newArray;
}
Re-shape a multi dimensional array to fit the specified dimensions
@param {Array} array           Array to be reshaped
@param {Array.<number>} sizes  List of sizes for each dimension
@returns {Array}               Array whose data has been formatted to fit the
                               specified dimensions

@throws {DimensionError}       If the product of the new dimension sizes does
                               not equal that of the old ones