From 43639c82158b46f2a67fb1183d6abad6563bc190 Mon Sep 17 00:00:00 2001 From: devartes Date: Mon, 24 Oct 2022 15:37:02 -0300 Subject: [PATCH] =?UTF-8?q?fix:=20substitui=C3=A7=C3=A3o=20do=20c=C3=B3dig?= =?UTF-8?q?o=20do=205=C2=B0=20desafio?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 05-é-primo/index.html | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/05-é-primo/index.html b/05-é-primo/index.html index e7ad135..25d6b17 100644 --- a/05-é-primo/index.html +++ b/05-é-primo/index.html @@ -16,28 +16,12 @@ */ function isPrime(number) { // implementar logica aqui - if (number === 2 || number === 3) return true - if (number % 2 === 0 || number < 2) return false - - var s = 0, - d = number - 1 - while ((d & 1) == 0) { - d >>= 1 - ++s - } - - let base = 2 - var x = Math.pow(base, d) % number - - if (x == 1 || x == number - 1) return true - - for (var i = 1; i <= s; i++) { - x = (x * x) % number - - if (x === number - 1) return true - } - return false - } + for (let i = 2; i < number; i++) + if (number % i === 0) { + return false; + } + return number > 1; + } // Resultados esperados console.log(isPrime(2), true) // true