function unique
unique(x: array): array

Unique values in an array or matrix.

Returns the unique values from an array or matrix. Optionally, returns the unique values along with their original indices.

Examples

Unique values from an array

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

assertEquals(unique([9, -3, 2, -12, 0, 1, 0, 1, 2, 3, 4, 5]), [-12, -3, 0, 1, 2, 3, 4, 5, 9]);

Unique values and their indices

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

assertEquals(unique([9, -3, 2, -12, 0, 1, 0, 1, 2, 3, 4, 5], 1), [[-12, -3, 0, 1, 2, 3, 4, 5, 9], [3, 1, 4, 5, 2, 9, 10, 11, 0]]);

Unique values from a matrix

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

assertEquals(unique([[5, 4], [5, 3], [6, 3]]), [3, 4, 5, 6]);

Unique values and indices from a matrix

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

assertEquals(unique([[5, 4], [5, 3], [6, 3]], 1), [[3, 4, 5, 6], [3, 1, 0, 4]]);

Parameters

The input array or matrix of values

Return Type

The unique values, or a matrix containing the unique values and their indices

Throws

If no input is provided or the flag is invalid

unique(
x: array,
flag: 0,
): array

Unique values in an array or matrix.

Returns the unique values from an array or matrix. Optionally, returns the unique values along with their original indices.

Examples

Unique values from an array

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

assertEquals(unique([9, -3, 2, -12, 0, 1, 0, 1, 2, 3, 4, 5]), [-12, -3, 0, 1, 2, 3, 4, 5, 9]);

Unique values and their indices

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

assertEquals(unique([9, -3, 2, -12, 0, 1, 0, 1, 2, 3, 4, 5], 1), [[-12, -3, 0, 1, 2, 3, 4, 5, 9], [3, 1, 4, 5, 2, 9, 10, 11, 0]]);

Unique values from a matrix

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

assertEquals(unique([[5, 4], [5, 3], [6, 3]]), [3, 4, 5, 6]);

Unique values and indices from a matrix

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

assertEquals(unique([[5, 4], [5, 3], [6, 3]], 1), [[3, 4, 5, 6], [3, 1, 0, 4]]);

Parameters

The input array or matrix of values

flag: 0

If 1, returns both unique values and their indices; if 0, returns only unique values (default is 0)

Return Type

The unique values, or a matrix containing the unique values and their indices

Throws

If no input is provided or the flag is invalid

unique(
x: array,
flag: 1,
): matrix

Unique values in an array or matrix.

Returns the unique values from an array or matrix. Optionally, returns the unique values along with their original indices.

Examples

Unique values from an array

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

assertEquals(unique([9, -3, 2, -12, 0, 1, 0, 1, 2, 3, 4, 5]), [-12, -3, 0, 1, 2, 3, 4, 5, 9]);

Unique values and their indices

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

assertEquals(unique([9, -3, 2, -12, 0, 1, 0, 1, 2, 3, 4, 5], 1), [[-12, -3, 0, 1, 2, 3, 4, 5, 9], [3, 1, 4, 5, 2, 9, 10, 11, 0]]);

Unique values from a matrix

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

assertEquals(unique([[5, 4], [5, 3], [6, 3]]), [3, 4, 5, 6]);

Unique values and indices from a matrix

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

assertEquals(unique([[5, 4], [5, 3], [6, 3]], 1), [[3, 4, 5, 6], [3, 1, 0, 4]]);

Parameters

The input array or matrix of values

flag: 1

If 1, returns both unique values and their indices; if 0, returns only unique values (default is 0)

Return Type

The unique values, or a matrix containing the unique values and their indices

Throws

If no input is provided or the flag is invalid

unique(x: matrix): array

Unique values in an array or matrix.

Returns the unique values from an array or matrix. Optionally, returns the unique values along with their original indices.

Examples

Unique values from an array

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

assertEquals(unique([9, -3, 2, -12, 0, 1, 0, 1, 2, 3, 4, 5]), [-12, -3, 0, 1, 2, 3, 4, 5, 9]);

Unique values and their indices

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

assertEquals(unique([9, -3, 2, -12, 0, 1, 0, 1, 2, 3, 4, 5], 1), [[-12, -3, 0, 1, 2, 3, 4, 5, 9], [3, 1, 4, 5, 2, 9, 10, 11, 0]]);

Unique values from a matrix

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

assertEquals(unique([[5, 4], [5, 3], [6, 3]]), [3, 4, 5, 6]);

Unique values and indices from a matrix

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

assertEquals(unique([[5, 4], [5, 3], [6, 3]], 1), [[3, 4, 5, 6], [3, 1, 0, 4]]);

Parameters

The input array or matrix of values

Return Type

The unique values, or a matrix containing the unique values and their indices

Throws

If no input is provided or the flag is invalid

unique(
x: matrix,
flag: 0,
): array

Unique values in an array or matrix.

Returns the unique values from an array or matrix. Optionally, returns the unique values along with their original indices.

Examples

Unique values from an array

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

assertEquals(unique([9, -3, 2, -12, 0, 1, 0, 1, 2, 3, 4, 5]), [-12, -3, 0, 1, 2, 3, 4, 5, 9]);

Unique values and their indices

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

assertEquals(unique([9, -3, 2, -12, 0, 1, 0, 1, 2, 3, 4, 5], 1), [[-12, -3, 0, 1, 2, 3, 4, 5, 9], [3, 1, 4, 5, 2, 9, 10, 11, 0]]);

Unique values from a matrix

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

assertEquals(unique([[5, 4], [5, 3], [6, 3]]), [3, 4, 5, 6]);

Unique values and indices from a matrix

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

assertEquals(unique([[5, 4], [5, 3], [6, 3]], 1), [[3, 4, 5, 6], [3, 1, 0, 4]]);

Parameters

The input array or matrix of values

flag: 0

If 1, returns both unique values and their indices; if 0, returns only unique values (default is 0)

Return Type

The unique values, or a matrix containing the unique values and their indices

Throws

If no input is provided or the flag is invalid

unique(
x: matrix,
flag: 1,
): matrix

Unique values in an array or matrix.

Returns the unique values from an array or matrix. Optionally, returns the unique values along with their original indices.

Examples

Unique values from an array

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

assertEquals(unique([9, -3, 2, -12, 0, 1, 0, 1, 2, 3, 4, 5]), [-12, -3, 0, 1, 2, 3, 4, 5, 9]);

Unique values and their indices

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

assertEquals(unique([9, -3, 2, -12, 0, 1, 0, 1, 2, 3, 4, 5], 1), [[-12, -3, 0, 1, 2, 3, 4, 5, 9], [3, 1, 4, 5, 2, 9, 10, 11, 0]]);

Unique values from a matrix

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

assertEquals(unique([[5, 4], [5, 3], [6, 3]]), [3, 4, 5, 6]);

Unique values and indices from a matrix

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

assertEquals(unique([[5, 4], [5, 3], [6, 3]], 1), [[3, 4, 5, 6], [3, 1, 0, 4]]);

Parameters

The input array or matrix of values

flag: 1

If 1, returns both unique values and their indices; if 0, returns only unique values (default is 0)

Return Type

The unique values, or a matrix containing the unique values and their indices

Throws

If no input is provided or the flag is invalid