Skip to content

sort

La fonction sort() trie un tableau de chaînes en ordre croissant (ASC) ou décroissant (DSC) et retourne un nouveau tableau.

Exemple interactif

Syntaxe

Signature classique

typescript
function sort<
  GenericArray extends readonly string[],
>(
  array: GenericArray,
  type: SortType,
): string[]

Signature currifiée

typescript
function sort<
  GenericArray extends readonly string[],
>(
  type: SortType,
): (array: GenericArray) => string[]

Paramètres

  • array : Tableau de chaînes à trier.
  • type : Ordre de tri, "ASC" (croissant) ou "DSC" (décroissant).

Valeur de retour

Un nouveau tableau de chaînes triées. Le tableau d'origine reste inchangé.

Voir aussi

  • concat - Concatène plusieurs chaînes
  • split - Découpe une chaîne en tableau

Diffusé sous licence MIT.