Function sort

  • Namespace

    ArrayUtils

    Sort an array in ascending or descending order.

    Type Parameters

    • T

      The type of elements in the array.

    Parameters

    • array: T[]

      An array of elements to sort.

    • sortOrder: SortOrder = SortOrder.ASC

      The sorting order, either 'ASC' for ascending or 'DESC' for descending.

    Returns T[]

    Returns a new sorted array without modifying the original array.

    Function

    sortArray

    Example

    const numbers = [5, 10, 2, 8];
    const sortedArray = sortArray(numbers, SortOrder.ASC);
    console.log(sortedArray); // Output: [2, 5, 8, 10]

    Example

    const strings = ['banana', 'apple', 'orange'];
    const sortedStrings = sortArray(strings, SortOrder.DESC);
    console.log(sortedStrings); // Output: ['orange', 'banana', 'apple']

Generated using TypeDoc