const array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
const reshape3d = arr => {
let result = []
let halves = []
let startIdx = 0
let smallChunk = 2
let bigChunk = 3
let copy = [...arr]
for(let i = 0; i < arr.length; i += smallChunk) {
halves.push(copy.splice(startIdx, smallChunk))
}
for(let i = 0; i <= halves.length; i += bigChunk) {
result.push(halves.splice(startIdx, bigChunk))
}
return result
}
console.log(
reshape3d(array)
)