danmatrix
    Preparing search index...

    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

    Index

    Constructors

    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

      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

      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 number of elements of the matrix

      Returns number

      the number of elements of the matrix

    • Get the matrix value at (x, y)

      Parameters

      • coord: Coordinates

        the Coordinates instance (x,y) for rows and columns

      Returns T | undefined

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

    • Get all the adjacent elements given a specific coordinate

      top-left top top-right
      left element right
      bottom-left bottom bottom-right

      Parameters

      • coord: Coordinates

        the coordinates of the element to get the adjacents from

      Returns DanMatrixElement<T>[] | undefined

      the list of adjacent elements

    • Get matrix column at columnIndex

      Parameters

      • columnIndex: number

        the column index

      Returns T[] | undefined

      the requested column as array of values

      Error if a wrong input is passed

    • 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 T[] | undefined

      the requested row as array of values

      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

      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

      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 Coordinates[]

      • an array of 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

      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

      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

      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

      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

      • coord: Coordinates

        the Coordinates instance (x,y) for rows and columns

      • val: T

        the value to set

      Returns T | undefined

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