You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Hydro/hydro/lib/rank.js

14 lines
314 B
JavaScript

function* ranked(diter, equ = (a, b) => a === b) {
let last = null;
let r = 0;
let count = 0;
for (const doc of diter) {
count++;
if (count === 1 || !equ(last, doc)) r = count;
last = doc;
yield [r, doc];
}
}
global.Hydro['lib.rank'] = module.exports = ranked;