stringComparatorAsc
比较器,用于字符串字典序升序排序。
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
比较器,用于数字升序排序。
Added in v0.0.1
Source
typescript
export const numberComparatorAsc = (a: number, b: number) => {
return a - b
}
numberComparatorDesc
比较器,用于数字降序排序。
Added in v0.0.1
Source
typescript
export const numberComparatorDesc = (a: number, b: number) => {
return b - a
}
codeUnitComparatorAsc
比较器,用于字符串根据 code unit value 升序排序。这是 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
比较器,用于字符串根据 code unit value 降序排序。
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
}