Class: Matrix

Matrix

Very simple object-backed bi-dimensional Matrix implementation.

new Matrix(inputMatrix)

Creates a Matrix instance; if specified the matrix is initialized with the given object.
Parameters:
Name Type Description
inputMatrix Object the matrix to initialize this object with.

Method Summary

del
Removes the element at the specified position in the matrix.
delRow
Removes the row at the specified position in the matrix.
forEachElement
Executes a given callback passing each element of the Matrix.
forEachElementInRow
Executes a given callback passing each element of the specified row.
forEachRow
Executes a given callback passing the key of each row containing at least one element.
get
Gets the element at the specified position in the matrix.
getEntireMatrix
getRow
insert
Inserts an element in the matrix.
insertRow
Inserts a full row in the matrix.
isEmpty
Verify if there are elements in the grid

Method Detail

del(row, column)

Removes the element at the specified position in the matrix.
Parameters:
Name Type Description
row String | Number the row in the matrix where the element is located.
column String | Number the column in the row where the element is located.

delRow(row)

Removes the row at the specified position in the matrix.
Parameters:
Name Type Description
row String | Number the row position.

forEachElement(callback)

Executes a given callback passing each element of the Matrix. The callback receives the element together with its coordinates.
Callbacks are executed synchronously before the method returns: calling insert or delete methods during callback execution may result in a wrong iteration.
Parameters:
Name Type Description
callback ForEachCallback The callback to be called.

forEachElementInRow(callback)

Executes a given callback passing each element of the specified row. The callback receives the element together with its coordinates.
Callbacks are executed synchronously before the method returns: calling insert or delete methods during callback execution may result in a wrong iteration.
Parameters:
Name Type Description
callback ForEachCallback The callback to be called.

forEachRow(callback)

Executes a given callback passing the key of each row containing at least one element.
Parameters:
Name Type Description
callback RowsCallback The callback to be called.

get(row, column) → {Object}

Gets the element at the specified position in the matrix. If the position is empty null is returned.
Parameters:
Name Type Description
row String | Number the row in the matrix where the element is located.
column String | Number the column in the row where the element is located.
Returns:
the element at the specified location or null.
Type
Object

getEntireMatrix()

Deprecated:
  • Yes

getRow()

Deprecated:
  • Yes

insert(insObject, row, column)

Inserts an element in the matrix. If another element is already present in the specified position it is overwritten.
Parameters:
Name Type Description
insObject Object the element to be added.
row String | Number the row in the matrix where the element is placed.
column String | Number the column in the row where the element is placed.

insertRow(insRow, row)

Inserts a full row in the matrix. If another row is already present in the specified position it is overwritten.
Parameters:
Name Type Description
insRow Object the row to be added.
row String | Number the row position.

isEmpty()

Verify if there are elements in the grid
Returns:
true if the matrix is empty, false otherwise