Array.prototype.reshape1d = function(nrow,ncol){
if (nrow< -1 || ncol < -1 || (nrow == -1 && ncol ==-1) ) throw new Error("bad shape")
if (nrow == -1){
if ( this.length % ncol != 0) throw new Error("bad shape")
nrow = this.length/ncol
} else if (ncol==-1){
if ( this.length % nrow != 0) throw new Error("bad shape")
ncol = this.length/nrow
}
console.log(nrow,ncol)
if (nrow*ncol != this.length) throw new Error("bad shape")
for (let row = 0; row < nrow; ++row) {
this.push(this.splice(0,ncol))
}
console.log(this)
return this
}