sortItems

Creates a sort items transformation action.

const Action = v.sortItems<TInput>(operation);

Generics

Parameters

  • operation ((itemA: TInput[number], itemB: TInput[number]) => number) | undefined

Explanation

With sortItems you can sort the items of an array based on a custom operation. This is a function that takes two items and returns a number. If the number is less than 0, the first item is sorted before the second item. If the number is greater than 0, the second item is sorted before the first. If the number is 0, the order of the items is not changed.

Returns

Examples

The following examples show how sortItems can be used.

Sort numbers

Schema that sorts the numbers in an array in ascending order.

const SortedArraySchema = v.pipe(v.array(v.number()), v.sortItems());

The following APIs can be combined with sortItems.

Schemas

Methods

Utils

Contributors

Thanks to all the contributors who helped make this page better!

  • GitHub profile picture of fabian-hiller

Partners

Thanks to our partners who support the project ideally and financially.

Sponsors

Thanks to our GitHub sponsors who support the project financially.

  • GitHub profile picture of antfu
  • GitHub profile picture of Thanaen
  • GitHub profile picture of osdiab
  • GitHub profile picture of ruiaraujo012
  • GitHub profile picture of hyunbinseo
  • GitHub profile picture of F0rce
  • GitHub profile picture of Unique-Pixels
  • GitHub profile picture of jdgamble555
  • GitHub profile picture of nickytonline
  • GitHub profile picture of KubaJastrz
  • GitHub profile picture of caegdeveloper
  • GitHub profile picture of dslatkin