function getrow
getrow(
x: matrix,
n: number,
): array

Get a row of a matrix.

Retrieves a specific row from a 2D matrix. If the input is not a matrix or if the row index is invalid, an error is thrown.

Examples

Get the first row

import { assertEquals, assertThrows } from "jsr:@std/assert";

assertEquals(getrow([[5, 6, 5], [7, 8, -1]], 0), [5, 6, 5]); // [5, 6, 5]

Get the second row

import { assertEquals, assertThrows } from "jsr:@std/assert";

assertEquals(getrow([[5, 6, 5], [7, 8, -1]], 1), [7, 8, -1]); // [7, 8, -1]

Invalid row index (out of bounds)

import { assertEquals, assertThrows } from "jsr:@std/assert";

assertThrows(() => { getrow([[5, 6, 5], [7, 8, -1]], 2); }, Error, 'Row index must be an integer between 0 and N - 1 rows');

Parameters

The input matrix (2D array) from which to retrieve the row.

n: number

The row index to retrieve (0-based index).

Return Type

An array representing the specified row of the matrix.

Throws

Throws an error if the input is not a matrix or if the row index is out of bounds.