Home
Getting Started
  • Fundamentals
  • Advanced
  • Fundamentals
  • Intermediate
  • Advanced
OM-Functions
  • FAQs
  • Glossary
  • Contributing
Changelog
Github
Home
Getting Started
  • Fundamentals
  • Advanced
  • Fundamentals
  • Intermediate
  • Advanced
OM-Functions
  • FAQs
  • Glossary
  • Contributing
Changelog
Github
  • OM-Functions

    • OM-Functions Overview
    • Arithmetic Operations
    • Array Operations
    • Logical Operations
    • Statistics
    • Transformations
    • Utilities

Transformations

These functions are used to reshape or reformat arrays:

1. mad.reshape(array, newShape)

Reshapes an array to the specified shape:

ParameterTypeDescription
arrayArrayThe original array
newShapeArrayNew shape, e.g., [2, 2]
ReturnsArrayReshaped array

Example:

import { reshape } from 'openmadness';

reshape([1, 2, 3, 4], [2, 2]);
// Result: [[1, 2], [3, 4]]

2. mad.flatten(array)

Flattens a nested array into a 1D array:

ParameterTypeDescription
arrayArrayA nested array
ReturnsArrayFlattened 1D array
ReturnsArrayReshaped array

Example:

import { flatten } from 'openmadness';

flatten([[1, 2], [3, 4]]);
// Result: [1, 2, 3, 4]

3. mad.transpose(array)

Transposes a 2D array (rows become columns):

ParameterTypeDescription
array2D ArrayThe matrix to flip
ReturnsArrayTransposed matrix
ReturnsArrayReshaped array

Example:

import { transpose } from 'openmadness';

transpose([[1, 2], [3, 4]]);
// Result: [[1, 3], [2, 4]]
Edit this page on GitHub
Last Updated:: 7/11/25, 12:24 PM
Contributors: Dev-Liz
Prev
Statistics
Next
Utilities