Creates a descending date comparator function for use with Array.prototype.sort().
Array.prototype.sort()
Items with null or undefined dates are treated as epoch (sorted last).
null
undefined
Accessor function that extracts a date value from each item
A comparator function that sorts items from newest to oldest
const prs = [{ createdAt: '2024-01-01' }, { createdAt: '2024-06-15' }];prs.sort(byDateDescending(pr => pr.createdAt));// [{ createdAt: '2024-06-15' }, { createdAt: '2024-01-01' }] Copy
const prs = [{ createdAt: '2024-01-01' }, { createdAt: '2024-06-15' }];prs.sort(byDateDescending(pr => pr.createdAt));// [{ createdAt: '2024-06-15' }, { createdAt: '2024-01-01' }]
Creates a descending date comparator function for use with
Array.prototype.sort().Items with
nullorundefineddates are treated as epoch (sorted last).