challenge-algorithms-v2.0-c.../05-isPrime/index.js

11 lines
303 B
JavaScript
Raw Permalink Normal View History

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;
}