Skip to content

stringComparatorAsc

Comparator for sorting strings in lexicographical ascending order.

Added in v0.0.1

Source

typescript
export const stringComparatorAsc = (a: string, b: string) => {
  return a.localeCompare(b)
}

stringComparatorDesc

Comparator for sorting strings in lexicographical descending order.

Added in v0.0.1

Source

typescript
export const stringComparatorDesc = (a: string, b: string) => {
  return b.localeCompare(a)
}

numberComparatorAsc

Comparator for sorting numbers in ascending order.

Added in v0.0.1

Source

typescript
export const numberComparatorAsc = (a: number, b: number) => {
  return a - b
}

numberComparatorDesc

Comparator for sorting numbers in descending order.

Added in v0.0.1

Source

typescript
export const numberComparatorDesc = (a: number, b: number) => {
  return b - a
}

codeUnitComparatorAsc

Comparator for sorting strings in ascending order based on their code unit values. This is the default order used by Array.prototype.sort in Vanilla JavaScript.

Added in v0.0.2

Source

typescript

export const codeUnitComparatorAsc = (a: string, b: string) => {
  if (a < b) return -1
  if (b > a) return 1
  return 0
}

codeUnitComparatorDesc

Comparator for sorting strings in descending order based on their code unit values.

Added in v0.0.2

Source

typescript
export const codeUnitComparatorDesc = (a: string, b: string) => {
  if (a < b) return 1
  if (b > a) return -1
  return 0
}