Наверное как-то так
function prettyPrint(data) {
console.log(JSON.stringify(data));
}
class Matrix3D {
constructor(len) {
this.x = len.x;
this.y = len.y;
this.z = len.z;
this.init();
}
init() {
const { x, y, z } = this;
this.buffer = Array.from(Array(z), (_, i) => {
return Array.from(Array(y), (_, j) => {
return Array.from(Array(x), (_, k) => {
return (j * x + k + 1) + (((x * y * z) / z) * i);
});
});
});
}
set(coords, value) {
this.buffer[coords.z][coords.y][coords.x] = value;
}
get(coords) {
return this.buffer[coords.z][coords.y][coords.x];
}
}
const matrix = new Matrix3D({x: 2, y: 2, z: 2});
matrix.init();
matrix.set({x: 1, y: 1, z: 1}, 10);
prettyPrint(matrix.get({x: 1, y: 1, z: 1}));
prettyPrint(matrix.buffer);
|