function clone
clone<T extends numarraymatrix>(x: T): T

Create a clone of the input array or matrix.

Creates a deep copy of the input array or matrix. If the input is a number, it simply returns that number.

Examples

Clone a matrix

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

assertEquals(clone([[-1, 3, -1], [4, 5, 9]]), [[-1, 3, -1], [4, 5, 9]]);

Clone an array

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

assertEquals(clone([5, 6, 3]), [5, 6, 3]);

Clone a single number

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

assertEquals(clone(5), 5);

Type Parameters

Parameters

x: T

Array or matrix to clone.

Return Type

A deep copy of the input array or matrix.

Throws

If no input is provided.