Constructor
new Grid(rows, cols)
- Source:
Constructs a grid.
Parameters:
Name | Type | Description |
---|---|---|
rows |
number | |
cols |
number |
Methods
get(row, col) → {any}
- Source:
Gets the object stored at the requested row and column.
Parameters:
Name | Type | Description |
---|---|---|
row |
number | The row of the desired object. |
col |
number | The col of the desired object. |
Returns:
The value stored in the grid
at that position.
- Type
- any
inBounds(row, col) → {boolean}
- Source:
Checks whether the given row and col exist in the grid.
Parameters:
Name | Type | Description |
---|---|---|
row |
number | Row of the position being checked. |
col |
number | Col of the position being checked. |
Returns:
Whether or not the given position is in bounds.
- Type
- boolean
init(value)
- Source:
Initializes the contents of the grid with `value`.
Parameters:
Name | Type | Description |
---|---|---|
value |
any | The value to be inserted in all positions of the grid. |
initFromArray(arr)
- Source:
Initializes a Grid from an array.
Parameters:
Name | Type | Description |
---|---|---|
arr |
array | Array containing elements to be made into a Grid. |
numCols() → {number}
- Source:
Returns the number of cols in the grid.
Returns:
The number of cols in the grid.
- Type
- number
numRows() → {number}
- Source:
Returns the number of rows in the grid.
Returns:
The number of rows in the grid.
- Type
- number
set(row, col, value)
- Source:
Sets an object at the requested row and column.
Parameters:
Name | Type | Description |
---|---|---|
row |
number | The row of the destination of the object. |
col |
number | The column of the destination of the object. |
value |
any | The value to be stored at the specified location in the grid |
toList() → {array}
- Source:
Converts a grid to a list.
For example:
-------
A B C D
E F G H
I J K L
-------
would convert to:
-------
[[0, 0, 'A'], [0, 1, 'B'], [0, 2, 'C'], [0, 3, 'D'], [1, 0, 'E']...[2, 3, 'L']]
Returns:
List representation of the Grid.
- Type
- array
toString() → {string}
- Source:
Generates a string representation of the Grid.
Returns:
A representation of a grid of the format
"A B C \nD E F \nG H I \n"
- Type
- string