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

コードユニット値に基づいて文字列を昇順にソートする比較関数です。これは Vanilla JavaScript の Array.prototype.sort で使用されるデフォルトの順序です。

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

コードユニット値に基づいて文字列を降順にソートする比較関数です。

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
}