From 117127ae3827a6b91d6171591c2c5204a71fa25e Mon Sep 17 00:00:00 2001 From: carloswinter Date: Fri, 28 Oct 2022 16:02:38 -0300 Subject: [PATCH] feat(isPrime): adiciona resolucao questao05-isprime --- 05-isPrime/index.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/05-isPrime/index.js b/05-isPrime/index.js index ec9c4ac..6e7afa2 100644 --- a/05-isPrime/index.js +++ b/05-isPrime/index.js @@ -1,4 +1,11 @@ export function isPrime(value) { // implementar logica aqui - + if (isNaN(value) || !isFinite(value) || value % 1 || value < 2) + return false; + if (value % 2 == 0) + return (value == 2); + for (let i = 3; i <= Math.sqrt(value); i += 2) { + if (value % i == 0) return false; + } + return true; } \ No newline at end of file -- 2.34.1