ismatrix(x: unknown): x is matrix
True for matrix (2D array with consistent row lengths).
Returns true if the input is a 2D array (array of arrays) where all subarrays have the same length.
Valid matrix with one row
Valid matrix with one row
import { assertEquals } from "jsr:@std/assert"; assertEquals(ismatrix([[1, 3, 4]]), true);
Valid matrix with multiple rows
Valid matrix with multiple rows
import { assertEquals } from "jsr:@std/assert"; assertEquals(ismatrix([[1], [3], [4]]), true);
Invalid matrix due to varying row lengths
Invalid matrix due to varying row lengths
import { assertEquals } from "jsr:@std/assert"; assertEquals(ismatrix([[1, 2], [3, 4, 5]]), false);
Valid matrix with mixed element types
Valid matrix with mixed element types
import { assertEquals } from "jsr:@std/assert"; assertEquals(ismatrix([[1, 2], [3, '4']]), true);
x is matrix
Returns true if x is a valid matrix.