I have a matrix and a flip_value that goes for the first element, I want to offset or push down the numbers of a selected column.
For example
let matrix = [
[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12],
[13, 14, 15, 16],
];
I want to change the matrix-like that:
So in the second (1st row in the program) is pushed down by 1 and the first element changed.
flip_value = 999
let matrix = [1, 999, 3, 4],
[5, 2, 7, 8],
[9, 6, 11, 12],
[13, 10, 15, 16],
The new flip value is 14.
Could you also give me a hint on how to do this from down to up?
flip_value = 999
Like that:
let matrix = [
[1, 6, 3, 4],
[5, 10, 7, 8],
[9, 14, 11, 12],
[13, 999, 15, 16],
];
//In this method the second-row values are pushed down to up by 1 and the last value in second row the last element flipped.
The new flip_value = 2 here
The whole code which is not working
let matrix = [
[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12],
[13, 14, 15, 16],
];
let Yindex = 1;
let flip_value = 999;
let size = 4;
let flip_tmp = matrix[size - 1][Yindex];
console.log("fontos");
for (let i = 1; i < size; i++) {
// matrix[i][Yindex] = matrix[i-1][Yindex];
let tmp = matrix[i][Yindex];
matrix[i][Yindex] = matrix[i - 1][Yindex];
matrix[i - 1][Yindex] = tmp;
console.log(matrix[i][Yindex] + "=" + matrix[i - 1][Yindex]);
}
matrix[0][Yindex] = flip_value;
flip_value = flip_tmp;
for (let i = 0; i < size; i++) {
console.log("n");
for (let j = 0; j < size; j++) {
console.log(matrix[i][j] + " ");
}
}
for (let i = 0; i < size; i++) {
console.log("n");
for (let j = 0; j < size; j++) {
if (j == 1) {
console.log(i + "" + j + " " + matrix[i][j] + " ");
}
}
}