function flipdim
flipdim(
x:
number
| array
| matrix
,
dim?: number,
):
number
| array
| matrix

Flip the order of elements in an array or matrix.

Flips the order of elements in an array or matrix along a specified dimension. Default dimension is 1 (columns).

Examples

Flip a 1D array (dim = 1)

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

assertEquals(flipdim([5, 6, 3], 1), [3, 6, 5]);

Flip a 1D array with no dimension specified (no change)

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

assertEquals(flipdim([5, 6, 3], 0), [5, 6, 3]);

Flip a 2D matrix along columns (dim = 1)

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

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

Flip a 2D matrix along rows (dim = 0)

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

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

Parameters

x:
number
| array
| matrix

The array or matrix to flip.

optional
dim: number = 1

The dimension to apply the flip (0 = rows, 1 = columns). Defaults to 1.

Return Type

number
| array
| matrix

The array or matrix with flipped elements.

Throws

If no input is provided.