I need help updating a matrix array. It starts with set values and i need to pass in coordinates to update the values.
I have a set base matrix:
var myMatrix = [
['-','-','-','-','-','-','-','-','-','-'],
['-','-','-','-','-','-','-','-','-','-'],
['-','-','-','-','-','-','-','-','-','-'],
['-','-','-','-','-','-','-','-','-','-'],
['-','-','-','-','-','-','-','-','-','-'],
['-','-','-','-','-','-','-','-','-','-'],
['-','-','-','-','-','-','-','-','-','-'],
['-','-','-','-','-','-','-','-','-','-'],
['-','-','-','-','-','-','-','-','-','-'],
['-','-','-','-','-','-','-','-','-','-']
];
I was able to update specific points in the matrix to read like so:
----x-----
-----x----
--------x-
--------x-
---x------
----------
-------x--
----------
----x-----
-------x--
with this 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 want to make another function that does something similar, it should take in value to update the matrix like so:
xxxxx-----
xxxxxx----
xxxxxxxxx-
xxxxxxxxx-
xxxx------
----------
xxxxxxxx--
----------
xxxxx-----
xxxxxxxx--
Basically pass in the row and how many '-'s to convert to 'x's.
JS Fiddle of my current work (stepThree is where I need help): https://jsfiddle.net/2vbd27f0/73/
Thanks in advanced for the help!