overleaf/services/contacts/app/js/contacts.js
Alf Eaton c14467b87a Migrate contacts service to ES modules (#10904)
GitOrigin-RevId: c5abb64729530baecbee0eb589eaed39faa2ac56
2022-12-19 09:03:55 +00:00

13 lines
390 B
JavaScript

export function buildContactIds(contacts, limit) {
return Object.entries(contacts || {})
.map(([id, { n, ts }]) => ({ id, n, ts }))
.sort(sortContacts)
.slice(0, limit)
.map(contact => contact.id)
}
// sort by decreasing count, decreasing timestamp.
// i.e. highest count, most recent first.
function sortContacts(a, b) {
return a.n === b.n ? b.ts - a.ts : b.n - a.n
}