simplify loop

This commit is contained in:
2019-11-23 23:45:30 +01:00
parent 06f01d2ef9
commit b3fe95c024

View File

@@ -5,10 +5,9 @@ const floyd = function(f, x0) {
let i = 0; let i = 0;
const map = new WeakMap(); const map = new WeakMap();
while (1) { while (!(x in map)) {
map[x] = i++; map[x] = i++;
x = f(x); x = f(x);
if (x in map) break;
} }
return [map[x], i - map[x]]; return [map[x], i - map[x]];