table-class v1.3.0
Table
Represents a two-dimensional array of data.
Kind: global class
Template: T Type of data that will be stored by this table.
- Table
- new Table(width, height, [callbackfn])
- instance
- .width : number
- .height : number
- .rows : Array.<Array.<?T>>
- .cols : Array.<Array.<?T>>
- .set(x, y, value) ⇒ Table.<T>
- .get(x, y) ⇒ T
- .row(y) ⇒ Array.<?T>
- .col(x) ⇒ Array.<?T>
- .map(callbackfn) ⇒ Table.<U>
- .reduce(callbackfn, initialValue) ⇒ U
- .forEach(callbackfn, [thisArg])
- .toString() ⇒ string
- .cw() ⇒ Table.<T>
- .ccw() ⇒ Table.<T>
- .flipX() ⇒ Table.<T>
- .flipY() ⇒ Table.<T>
- static
- .fromRows(rows) ⇒ Table.<U>
- .fromCols(cols) ⇒ Table.<U>
- inner
- ~constructorCallback ⇒ T
- ~mapCallback ⇒ U
- ~reduceCallback ⇒ U
- ~forEachCallback : function
new Table(width, height, callbackfn)
Creates an instance of Table.
Param | Type | Description |
---|---|---|
width | number | Horizontal size of the array. |
height | number | Vertical size of the array. |
callbackfn | constructorCallback | This function is used to populate table during initialization. |
table.width : number
Horizontal size of the array
Kind: instance property of Table
Read only: true
table.height : number
Vertical size of the array.
Kind: instance property of Table
Read only: true
table.rows : Array.<Array.<?T>>
Table data organized by rows.
Kind: instance property of Table
Read only: true
table.cols : Array.<Array.<?T>>
Table data organized by columns.
Kind: instance property of Table
Read only: true
table.set(x, y, value) ⇒ Table.<T>
Sets a value at given coordinates.
If one of the coordinates equals null, value will be set for the whole row/column.
Kind: instance method of Table
Returns: Table.<T> - This table.
Param | Type | Description |
---|---|---|
x | number | X index. |
y | number | Y index. |
value | T | Value to be set. |
table.get(x, y) ⇒ T
Returns value at given coordinates.
Kind: instance method of Table
Returns: T - Value at given coordinates.
Param | Type | Description |
---|---|---|
x | number | X index. |
y | number | Y index. |
table.row(y) ⇒ Array.<?T>
Returns a specific row.
Kind: instance method of Table
Returns: Array.<?T> - Row of data.
Param | Type | Description |
---|---|---|
y | number | Index of a row to be returned. |
table.col(x) ⇒ Array.<?T>
Returns a specific column.
Kind: instance method of Table
Returns: Array.<?T> - Column of data.
Param | Type | Description |
---|---|---|
x | number | Index of a column to be returned. |
table.map(callbackfn) ⇒ Table.<U>
Creates new table using this table values.
Kind: instance method of Table
Returns: Table.<U> - New table.
Template: U Type of data that will be stored by new table.
Param | Type | Description |
---|---|---|
callbackfn | mapCallback | This function is used to populate new table using current table values. |
table.reduce(callbackfn, initialValue) ⇒ U
Calls the specified callback function for all table values and returns accumulation result.
Kind: instance method of Table
Returns: U - Accumulation result.
Template: U Type of accumulation result.
Param | Type | Description |
---|---|---|
callbackfn | reduceCallback | The reduce method calls this function one time for each value of the table. |
initialValue | U | If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of a table value. |
table.forEach(callbackfn, thisArg)
Performs the specified action for each element in a table.
Kind: instance method of Table
Param | Type | Description |
---|---|---|
callbackfn | forEachCallback | Function called one time for each element in the table. |
thisArg | * | An object to which the this keyword can refer in the callbackfn function. |
table.toString() ⇒ string
Returns a string representation of this table.
Kind: instance method of Table
Returns: string - String representation of table.
table.cw() ⇒ Table.<T>
Rotates table clockwise.
Kind: instance method of Table
Returns: Table.<T> - New table.
table.ccw() ⇒ Table.<T>
Rotates table counterclockwise.
Kind: instance method of Table
Returns: Table.<T> - New table.
table.flipX() ⇒ Table.<T>
Flips table horizontally.
Kind: instance method of Table
Returns: Table.<T> - New table.
table.flipY() ⇒ Table.<T>
Flips table vertically.
Kind: instance method of Table
Returns: Table.<T> - New table.
Table.fromRows(rows) ⇒ Table.<U>
Returns a new table populated with values from given array.
It handles variable rows length by setting null for missing values.
Kind: static method of Table
Returns: Table.<U> - New table with given values.
Template: U Type of data that will be stored by new table.
Param | Type | Description |
---|---|---|
rows | Array.<Array.<?U>> | Table data organized by rows. |
Table.fromCols(cols) ⇒ Table.<U>
Returns a new table populated with values from given array.
It handles variable columns length by setting null for missing values.
Kind: static method of Table
Returns: Table.<U> - New table with given values.
Template: U Type of data that will be stored by new table.
Param | Type | Description |
---|---|---|
cols | Array.<Array.<?U>> | Table data organized by columns. |
Table~constructorCallback ⇒ T
Kind: inner typedef of Table
Returns: T - Value for given coordinates.
Param | Type | Description |
---|---|---|
x | number | X coordinate. |
y | number | Y coordinate. |
Table~mapCallback ⇒ U
Kind: inner typedef of Table
Returns: U - New value for given coordinates.
Param | Type | Description |
---|---|---|
value | T | Current value at given coordinates. |
x | number | X coordinate. |
y | number | Y coordinate. |
table | Table.<T> | Current table. |
Table~reduceCallback ⇒ U
Kind: inner typedef of Table
Returns: U - Accumulation result.
Param | Type | Description |
---|---|---|
previousValue | U | Previous accumulation result. |
currentValue | T | Value at given coordinates. |
currentX | number | X coordinate. |
currentY | number | Y coordinate. |
table | Table.<T> | Current table. |
Table~forEachCallback : function
Kind: inner typedef of Table
Param | Type | Description |
---|---|---|
value | T | Value at given coordinates. |
x | number | X coordinate. |
y | number | Y coordinate. |
table | Table.<T> | Current table. |