Could anyone assist me with updating a matrix array? I have an initial matrix with preset values and need to update specific coordinates within it.
Here is the base matrix:
var myMatrix = [
['-','-','-','-','-','-','-','-','-','-'],
['-','-','-','-','-','-','-','-','-','-'],
['-','-','-','-','-','-','-','-','-','-'],
['-','-','-','-','-','-','-','-','-','-'],
['-','-','-','-','-','-','-','-','-','-'],
['-','-','-','-','-','-','-','-','-','-'],
['-','-','-','-','-','-','-','-','-','-'],
['-','-','-','-','-','-','-','-','-','-'],
['-','-','-','-','-','-','-','-','-','-'],
['-','-','-','-','-','-','-','-','-','-']
];
I managed to update certain points in the matrix, resulting in:
----x-----
-----x----
--------x-
--------x-
---x------
----------
-------x--
----------
----x-----
-------x--
This was done using the following function:
function stepTwo(coordinates) {
console.log('Step Two');
for(var j =0; j < coordinates.length; j ++) {
myMatrix[coordinates[j].y][coordinates[j].x] = 'x';
}
for(var i = 0; i < myMatrix.length; i++) {
console.log(myMatrix[i].join(' '));
}
}
var coordinatesArray = [
{x: 4, y: 0},
{x: 5, y: 1},
{x: 8, y: 2},
{x: 8, y: 3},
{x: 3, y: 4},
{x: 7, y: 6},
{x: 4, y: 8},
{x: 7, y: 9},
];
stepTwo(coordinatesArray);
Now I am looking to create another function that updates the matrix like this:
xxxxx-----
xxxxxx----
xxxxxxxxx-
xxxxxxxxx-
xxxx------
----------
xxxxxxxx--
----------
xxxxx-----
xxxxxxxx--
The new function should take in a row and convert a specified number of '-'s to 'x's.
For reference, here is a JSFiddle link showcasing my current progress (looking for help specifically with "stepThree"): https://jsfiddle.net/2vbd27f0/73/
Thank you in advance for any assistance provided!