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.
15 lines
317 B
TypeScript
15 lines
317 B
TypeScript
5 years ago
|
function* ranked(diter, equ = (a, b) => a === b) {
|
||
5 years ago
|
let last = null;
|
||
|
let r = 0;
|
||
|
let count = 0;
|
||
|
for (const doc of diter) {
|
||
5 years ago
|
count++;
|
||
5 years ago
|
if (count === 1 || !equ(last, doc)) r = count;
|
||
|
last = doc;
|
||
5 years ago
|
yield [r, doc];
|
||
|
}
|
||
5 years ago
|
}
|
||
|
|
||
4 years ago
|
global.Hydro.lib.rank = ranked;
|
||
|
export default ranked;
|