Files
actual/node_modules/@docsearch/react/dist/esm/utils/groupBy.js
Rich In SQL 28d4ee94dd Init
2022-10-16 20:28:33 +01:00

17 lines
387 B
JavaScript

export function groupBy(values, predicate) {
return values.reduce(function (acc, item) {
var key = predicate(item);
if (!acc.hasOwnProperty(key)) {
acc[key] = [];
} // We limit each section to show 5 hits maximum.
// This acts as a frontend alternative to `distinct`.
if (acc[key].length < 5) {
acc[key].push(item);
}
return acc;
}, {});
}