src/utils/array.js
function _reshape (array, sizes) {
  // testing if there are enough elements for the requested shape
  let tmpArray = array
  let tmpArray2
  // for each dimensions starting by the last one and ignoring the first one
  for (let sizeIndex = sizes.length - 1; sizeIndex > 0; sizeIndex--) {
    const size = sizes[sizeIndex]
    tmpArray2 = []

    // aggregate the elements of the current tmpArray in elements of the requested size
    const length = tmpArray.length / size
    for (let i = 0; i < length; i++) {
      tmpArray2.push(tmpArray.slice(i * size, (i + 1) * size))
    }
    // set it as the new tmpArray for the next loop turn or for return
    tmpArray = tmpArray2
  }

  return tmpArray
}
function _reshape (array, sizes) {
  // testing if there are enough elements for the requested shape
  let tmpArray = array
  let tmpArray2
  // for each dimensions starting by the last one and ignoring the first one
  for (let sizeIndex = sizes.length - 1; sizeIndex > 0; sizeIndex--) {
    const size = sizes[sizeIndex]
    tmpArray2 = []

    // aggregate the elements of the current tmpArray in elements of the requested size
    const length = tmpArray.length / size
    for (let i = 0; i < length; i++) {
      tmpArray2.push(tmpArray.slice(i * size, (i + 1) * size))
    }
    // set it as the new tmpArray for the next loop turn or for return
    tmpArray = tmpArray2
  }

  return tmpArray
}
function _reshape ( array , sizes ) { // testing if there are enough elements for the requested shape let tmpArray = array let tmpArray2 // for each dimensions starting by the last one and ignoring the first one for ( let sizeIndex = sizes . length - 1 ; sizeIndex > 0 ; sizeIndex -- ) { const size = sizes [ sizeIndex ] tmpArray2 = [ ] // aggregate the elements of the current tmpArray in elements of the requested size const length = tmpArray . length / size for ( let i = 0 ; i < length ; i ++ ) { tmpArray2 . push ( tmpArray . slice ( i * size , ( i + 1 ) * size ) ) } // set it as the new tmpArray for the next loop turn or for return tmpArray = tmpArray2 } return tmpArray }
Iteratively 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
Iteratively re - shape a multi dimensional array to fit the specified dimensions