From b3fe95c024f242998cbcf4964de102e8526d54e6 Mon Sep 17 00:00:00 2001 From: Grzegorz Kucmierz Date: Sat, 23 Nov 2019 23:45:30 +0100 Subject: [PATCH] simplify loop --- cycle-detection-floyds-the-tortoise-and-the-the-hare/index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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]];