function issquare
issquare(x: unknown): boolean

Checks if the input is a square matrix.

Returns true if the input matrix has the same number of rows and columns, otherwise returns false.

Examples

Valid square matrix

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

assertEquals(issquare([[9, 5], [6, 1]]), true);

Non-square matrix (more rows than columns)

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

assertEquals(issquare([[9, 5], [6, 1], [7, 8]]), false);

Non-square matrix (more columns than rows)

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

assertEquals(issquare([[9, 5, 3], [6, 1, 7]]), false);

Single element (1x1 matrix)

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

assertEquals(issquare([[9]]), true);

Empty matrix (should throw an error)

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

assertThrows(() => { issquare([]) }, Error);

Invalid input (not a matrix)

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

assertThrows(() => { issquare(123) }, Error);

Parameters

x: unknown

The input matrix to check.

Return Type

boolean

Returns true if x is a square matrix, otherwise false.

Throws

Throws an error if no arguments are provided or if the input is not a valid matrix.