new Grid(rows, cols)
- Source:
Parameters:
Name | Type | Description |
---|---|---|
rows |
rows
|
Number of rows in the grid. |
cols |
cols
|
Number of cols in the grid. |
Methods
get(row, col) → {number|string|object|boolean}
Gets the object stored at the requested row and column.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
row |
number
|
The row of the desired object. |
col |
number
|
The col of the desired object. |
Returns:
- Type:
-
number
|string
|object
|boolean
The value stored in the grid
at that position.
inBounds(row, col) → {boolean}
Checks whether the given row and col exist in the grid.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
row |
number
|
Row of the position being checked. |
col |
number
|
Col of the position being checked. |
Returns:
- Type:
-
boolean
Whether or not the given position is in bounds.
init(value)
Initializes the contents of the grid with `value`.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
value |
number
|
string
|
object
|
boolean
|
The value to be inserted in all positions of the grid. |
initFromArray(arr)
Initializes a Grid from an array.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
arr |
array
|
Array containing elements to be made into a Grid. |
numCols() → {number}
Returns the number of cols in the grid.
- Source:
Returns:
- Type:
-
number
The number of cols in the grid.
numRows() → {number}
Returns the number of rows in the grid.
- Source:
Returns:
- Type:
-
number
The number of rows in the grid.
set(row, col, value)
Sets an object at the requested row and column.
- Source:
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 |
number
|
string
|
object
|
boolean
|
The value to be stored at the specified location in the grid |
toList() → {array}
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']]
- Source:
Returns:
- Type:
-
array
List representation of the Grid.
toString() → {string}
Generates a string representation of the Grid.
- Source:
Returns:
- Type:
-
string
A representatino of a grid of the format
"A B C \nD E F \nG H I \n"