A function that orders two values: negative when a comes first, positive when b comes first, zero when they are equal in this order. Only the sign is used.
a
b
It is the shape Array.prototype.sort accepts.
Array.prototype.sort
const byLength: Comparator<string> = (a, b) => a.length - b.length['ccc', 'a', 'bb'].sort(byLength) // ['a', 'bb', 'ccc'] Copy
const byLength: Comparator<string> = (a, b) => a.length - b.length['ccc', 'a', 'bb'].sort(byLength) // ['a', 'bb', 'ccc']
A function that orders two values: negative when
acomes first, positive whenbcomes first, zero when they are equal in this order. Only the sign is used.It is the shape
Array.prototype.sortaccepts.