Skip to content

sort

sort() sorts an array of primitives (String, Number, Date, or Time) in "ASC" or "DSC". The array must stay homogeneous by primitive family, but can mix wrapped and raw values. Supports the curried version to integrate easily in a pipeline.

Interactive example

Syntax

Classic signature

typescript
function sort<
	GenericInput extends Primitives
>(
	input: GenericInput, 
	type: SortType
): ToWrappedValue<GenericInput[number]>[]

GenericInput is a homogeneous array from one of these families: Date | TheDate, Time | TheTime, Number | number, String | string.

Curried signature

typescript
function sort<
	GenericInput extends Primitives
>(
	type: SortType
): (
	input: GenericInput
) => ToWrappedValue<GenericInput[number]>[]

Parameters

  • input : homogeneous array of primitives (wrapped or raw) from the same family.
  • type : "ASC" or "DSC".

Return value

A new sorted array, whose elements are wrapped.

Released under the MIT license.