mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-18 01:36:08 +08:00
14 lines
314 B
JavaScript
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;
|