Как записать компактней, но чтобы читаемость кода сохранилась?
/**
* @returns {Array.<Node>}
* @private
*/
__getChildren() {
var matrix = this[__MATRIX];
var {width, height} = matrix.getSizes();
var vector = matrix.findCellVector(cell => !isNumber(cell));
var children = [];
if (vector[0] !== 0) {
let matrixClone = Matrix.clone();
let vectorClone = vector.clone();
vectorClone[0] -= 1;
matrixClone.swapCells(vector, vectorClone);
children.push(new Node({matrix: matrixClone}));
}
if (vector[0] !== width - 1) {
let matrixClone = Matrix.clone();
let vectorClone = vector.clone();
vectorClone[0] += 1;
matrixClone.swapCells(vector, vectorClone);
children.push(new Node({matrix: matrixClone}));
}
if (vector[1] !== 0) {
let matrixClone = Matrix.clone();
let vectorClone = vector.clone();
vectorClone[1] -= 1;
matrixClone.swapCells(vector, vectorClone);
children.push(new Node({matrix: matrixClone}));
}
if (vector[1] !== height - 1) {
let matrixClone = Matrix.clone();
let vectorClone = vector.clone();
vectorClone[1] += 1;
matrixClone.swapCells(vector, vectorClone);
children.push(new Node({matrix: matrixClone}));
}
return children;
}