Class DanMatrix<T>

DanMatrix is a class to handle two-dimension vectors, or matrices

Type Parameters

  • T

    is the type of element storable in the matrix

Constructors

Properties

_2dvector: T[][]

The data structure containing the real data.

It's defined as an Array of Array of T

Type Param: T

is the type of element storable in the matrix

Methods

  • Add a column to the matrix

    Parameters

    • column: T[]

      the column to be added

    Returns boolean

    true if the new column was correctly added, otherwise it returns false

    Throws

    Error if a wrong input is passed

  • Add a row to the matrix

    Parameters

    • row: T[]

      the row to be added

    Returns boolean

    true if the new row was correctly added, otherwise it returns false

    Throws

    Error if a wrong input is passed

  • Get the number of columns of the matrix

    Returns number

    the number of columns of the matrix

  • Get the matrix value at (x, y)

    Parameters

    • x: number

      the x coordinate (index of the rows)

    • y: number

      the y coordinate (index of the columns)

    Returns undefined | T

    the value at (x, y) or undefined if the coordinates are wrong

  • Get matrix column at columnIndex

    Parameters

    • columnIndex: number

      the column index

    Returns undefined | T[]

    the requested column as array of values

    Throws

    Error if a wrong input is passed

  • Get the matrix value at coord

    Parameters

    • coord: string

      a string representation of the coordinates using the dash '-' as separator. Example: "1-4" represents x:1 and y:4

    Returns undefined | T

    the value at coord or undefined if the string coordinates are wrong

  • Get a string representation of the current DanMatrix instance

    Parameters

    • fixedSpacing: number = 15

      an optional numeric value for the cell spacing (default is 15)

    Returns string

    a string representation of the current DanMatrix instance

  • Get matrix row at rowIndex

    Parameters

    • rowIndex: number

      the row index

    Returns undefined | T[]

    the requested row as array of values

    Throws

    Error if a wrong input is passed

  • Insert a column at the specific columnIndex index

    Parameters

    • columnIndex: number

      the column index

    • column: T[]

      the column to insert as an array of values

    Returns boolean

    true if the new column was correctly inserted, otherwise it returns false

    Throws

    Error if a wrong input is passed

  • Insert a row at the specific rowIndex index

    Parameters

    • rowIndex: number

      the row index

    • row: T[]

      the row to insert as an array of values

    Returns boolean

    true if the new row was correctly inserted, otherwise it returns false

    Throws

    Error if a wrong input is passed

  • Look for a specific value inside the matrix

    Parameters

    • val: T

      the value you're looking for

    Returns string[]

    • an array of string coordinates where the value was found
  • Remove matrix column at index 'columnIndex'

    Parameters

    • columnIndex: number

      the index of the column to be removed. If it's not an integer number or if it's less than zero, an exception "Error('Wrong input')" is thrown

    Returns boolean

    true if the column removal was successful, otherwise it returns false

    Throws

    exception "Error('Wrong input')" when any parameter in input is wrong

  • Remove matrix row at index 'rowIndex'

    Parameters

    • rowIndex: number

      the index of the row to be removed. If it's not an integer number or if it's less than zero, an exception "Error('Wrong input')" is thrown

    Returns boolean

    true if the row removal was successful, otherwise it returns false

    Throws

    exception "Error('Wrong input')" when any parameter in input is wrong

  • Replace matrix column at index 'columnIndex'

    Parameters

    • columnIndex: number

      the index of the column to be replaced. If it's not an integer number or if it's less than zero, an exception "Error('Wrong input')" is thrown

    • column: T[]

      the array of values which must replace the existing column. If it's not an array or if the array is empty, an exception "Error('Wrong input')" is thrown

    Returns boolean

    true if the column replacement was successful, otherwise it returns false

    Throws

    exception "Error('Wrong input')" when any parameter in input is wrong

  • Replace matrix row at index 'rowIndex'

    Parameters

    • rowIndex: number

      the index of the row to be replaced. If it's not an integer number or if it's less than zero, an exception "Error('Wrong input')" is thrown

    • row: T[]

      the array of values which must replace the existing row. If it's not an array or if the array is empty, an exception "Error('Wrong input')" is thrown

    Returns boolean

    true if the row replacement was successful, otherwise it returns false

    Throws

    exception "Error('Wrong input')" when any parameter in input is wrong

  • Get the number of rows of the matrix

    Returns number

    the number of rows of the matrix

  • Set a value at (x, y)

    Parameters

    • x: number

      the x coordinate (index of the rows)

    • y: number

      the y coordinate (index of the columns)

    • val: T

      the value to set

    Returns undefined | T

    the new value set at (x, y) or undefined if the coordinates are wrong

  • Set a value at coord

    Parameters

    • coord: string

      a string representation of the coordinates using the dash '-' as separator. Example: "1-4" represents x:1 and y:4

    • val: T

      the value to set

    Returns undefined | T

    the value at coord or undefined if the string coordinates are wrong

  • The public method to setup the matrix

    Parameters

    Returns void

    Throws

    Error if a wrong input is passed

Generated using TypeDoc