squeeze<T>(x: NestedArray<T>): NestedArray<T>
Removes singleton dimensions from arrays or matrices.
This function simplifies the shape of an array or matrix by removing singleton dimensions (dimensions of size 1). If the input is a number or a string, it returns the input as-is, since they don't have dimensions to squeeze.
Squeeze deeply nested arrays
Squeeze deeply nested arrays
import { assertEquals } from "jsr:@std/assert"; assertEquals(squeeze([[[[[8]]]]]), [[8]]);
Squeeze nested arrays with multiple elements
Squeeze nested arrays with multiple elements
import { assertEquals } from "jsr:@std/assert"; assertEquals(squeeze([[[[3, 4, 5]]]]), [[3, 4, 5]]);
Squeeze nested arrays with 2D content
Squeeze nested arrays with 2D content
import { assertEquals } from "jsr:@std/assert"; assertEquals(squeeze([[[[[['31-12-2014', '31-01-2015'], ['15-02-2015', '01-03-2015']]]]]]), [ ['31-12-2014', '31-01-2015'], ['15-02-2015', '01-03-2015'] ]);
x: NestedArray<T>
The input to squeeze
The squeezed input with singleton dimensions removed