feat: search in progress

This commit is contained in:
Daniel Avila 2023-03-16 21:20:40 -04:00
parent 9995a159aa
commit 6d2f3361d0
6 changed files with 84 additions and 24 deletions

View file

@ -0,0 +1,26 @@
const mergeSort = require('./mergeSort');
function reduceHits(hits) {
const counts = {};
for (const hit of hits) {
if (!counts[hit.conversationId]) {
counts[hit.conversationId] = 1;
} else {
counts[hit.conversationId]++;
}
}
const result = [];
for (const [conversationId, count] of Object.entries(counts)) {
result.push({
conversationId,
count
});
}
return mergeSort(result, (a, b) => b.count - a.count);
}
module.exports = reduceHits;