https://github.com/robert-ryu7/table-class
Utility class for easier handling of two-dimensional arrays.
https://github.com/robert-ryu7/table-class
Last synced: about 1 year ago
JSON representation
Utility class for easier handling of two-dimensional arrays.
- Host: GitHub
- URL: https://github.com/robert-ryu7/table-class
- Owner: robert-ryu7
- Created: 2018-07-03T13:05:58.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-07-09T10:55:32.000Z (almost 8 years ago)
- Last Synced: 2025-02-24T19:51:53.721Z (over 1 year ago)
- Language: JavaScript
- Size: 114 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
## Table
Represents a two-dimensional array of data.
**Kind**: global class
**Template**: T Type of data that will be stored by this table.
* [Table](#Table)
* [new Table(width, height, [callbackfn])](#new_Table_new)
* _instance_
* [.width](#Table+width) : number
* [.height](#Table+height) : number
* [.rows](#Table+rows) : Array.<Array.<?T>>
* [.cols](#Table+cols) : Array.<Array.<?T>>
* [.set(x, y, value)](#Table+set) ⇒ Table.<T>
* [.get(x, y)](#Table+get) ⇒ T
* [.row(y)](#Table+row) ⇒ Array.<?T>
* [.col(x)](#Table+col) ⇒ Array.<?T>
* [.map(callbackfn)](#Table+map) ⇒ Table.<U>
* [.reduce(callbackfn, initialValue)](#Table+reduce) ⇒ U
* [.forEach(callbackfn, [thisArg])](#Table+forEach)
* [.toString()](#Table+toString) ⇒ string
* [.cw()](#Table+cw) ⇒ Table.<T>
* [.ccw()](#Table+ccw) ⇒ Table.<T>
* [.flipX()](#Table+flipX) ⇒ Table.<T>
* [.flipY()](#Table+flipY) ⇒ Table.<T>
* _static_
* [.fromRows(rows)](#Table.fromRows) ⇒ Table.<U>
* [.fromCols(cols)](#Table.fromCols) ⇒ Table.<U>
* _inner_
* [~constructorCallback](#Table..constructorCallback) ⇒ T
* [~mapCallback](#Table..mapCallback) ⇒ U
* [~reduceCallback](#Table..reduceCallback) ⇒ U
* [~forEachCallback](#Table..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](#Table..constructorCallback) | This function is used to populate table during initialization. |
### table.width : number
Horizontal size of the array
**Kind**: instance property of [Table](#Table)
**Read only**: true
### table.height : number
Vertical size of the array.
**Kind**: instance property of [Table](#Table)
**Read only**: true
### table.rows : Array.<Array.<?T>>
Table data organized by rows.
**Kind**: instance property of [Table](#Table)
**Read only**: true
### table.cols : Array.<Array.<?T>>
Table data organized by columns.
**Kind**: instance property of [Table](#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](#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](#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](#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](#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](#Table)
**Returns**: Table.<U> - New table.
**Template**: U Type of data that will be stored by new table.
| Param | Type | Description |
| --- | --- | --- |
| callbackfn | [mapCallback](#Table..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](#Table)
**Returns**: U - Accumulation result.
**Template**: U Type of accumulation result.
| Param | Type | Description |
| --- | --- | --- |
| callbackfn | [reduceCallback](#Table..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](#Table)
| Param | Type | Description |
| --- | --- | --- |
| callbackfn | [forEachCallback](#Table..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](#Table)
**Returns**: string - String representation of table.
### table.cw() ⇒ Table.<T>
Rotates table clockwise.
**Kind**: instance method of [Table](#Table)
**Returns**: Table.<T> - New table.
### table.ccw() ⇒ Table.<T>
Rotates table counterclockwise.
**Kind**: instance method of [Table](#Table)
**Returns**: Table.<T> - New table.
### table.flipX() ⇒ Table.<T>
Flips table horizontally.
**Kind**: instance method of [Table](#Table)
**Returns**: Table.<T> - New table.
### table.flipY() ⇒ Table.<T>
Flips table vertically.
**Kind**: instance method of [Table](#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](#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](#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](#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](#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](#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](#Table)
| Param | Type | Description |
| --- | --- | --- |
| value | T | Value at given coordinates. |
| x | number | X coordinate. |
| y | number | Y coordinate. |
| table | Table.<T> | Current table. |