diff --git a/cycle-detection-floyds-the-tortoise-and-the-the-hare/index.js b/cycle-detection-floyds-the-tortoise-and-the-the-hare/index.js index a66d72b..534695f 100644 --- a/cycle-detection-floyds-the-tortoise-and-the-the-hare/index.js +++ b/cycle-detection-floyds-the-tortoise-and-the-the-hare/index.js @@ -5,10 +5,9 @@ const floyd = function(f, x0) { let i = 0; const map = new WeakMap(); - while (1) { + while (!(x in map)) { map[x] = i++; x = f(x); - if (x in map) break; } return [map[x], i - map[x]];