A fixed size 2D array in javascript
npm install fixed-2d-array
> A fixed size 2D array in JavaScript
This module gives you a two-dimensional array with a fixed size. The top left coordinate is (0,0).
rows is the number of rows the Fixed2DArray will start with, columns is the columns.defaultValue will be assigned to all elements.validateCoords method checks if the given coordinates are valid. (lie inside of the array)Error is thrown.validateCoords.value. The coordinate is checked using validateCoords.Only arguments that are arrays will be appended as rows.
If the given array is smaller then the height of the Fixed2DArray, undefined will fill
the given array until it is the same length as the current row.
For example, distance not set:
```
[ ][ ][ ][ ][ ]
[ ][][][*][ ]
[ ][][X][][ ]
[ ][][][*][ ]
[ ][ ][ ][ ][ ]
The given coordinate is marked with an X. The function will return an array containing the values for the fields marked with an *.
Example, distance = 2:
``
[][][][][*]
[][][][][*]
[][][X][][]
[][][][][*]
[][][][][*]
The function will return an array containing the values for the fields marked with an '*'. Notice that distance will change what cells count as neighbors.
The distance between each coordinate must be within distance or one unit away from each other for the
given coordinates to be considered neighbors.
For example, distance not set:
``
0 1 2
0 [A][ ][ ]
1 [ ][B][ ]
2 [ ][ ][ ]
3 [ ][ ][ ]
The first given coordinate (0,0) is marked with an A, the second (1,1), a B.
A and B are neighbors.
If A and B were instead placed at (0,0) and (2,2) respectively, like this:
``
0 1 2
0 [A][ ][ ]
1 [ ][ ][ ]
2 [ ][ ][B]
3 [ ][ ][ ]
A and B are no longer neighbors.
Example, distance = 2:
``
0 1 2
0 [A][ ][ ]
1 [ ][ ][ ]
2 [ ][ ][B]
3 [ ][ ][ ]
A (0,0) and B (2,2) are neighbors.
fn is the function to execute for each element, taking three arguments: currentValue
* : The current element being processed in the array.index
* : The object index, {x: x, y: y}, of the current element being processed in the 2d array.array
* : The Fixed2DArray that forEach is being applied to. thisArg`: Optional. Value to use as this when executing callback.
*