Skip to content

Commit

Permalink
Reto mouredev#21 - Javascript
Browse files Browse the repository at this point in the history
  • Loading branch information
Cesarpinagon committed Nov 18, 2023
1 parent dd60790 commit b95dab4
Showing 1 changed file with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function isPrime(num) {
for(let i = 2, sqrt = Math.sqrt(num); i <= sqrt; i++)
if(num % i === 0) return false;
return num > 1;
}

function findTwinPrimes(n) {
let twinPrimes = [];
for(let i = 2; i <= n - 2; i++) {
if(isPrime(i) && isPrime(i + 2)) {
twinPrimes.push([i, i + 2]);
}
}
return twinPrimes;
}

console.log(findTwinPrimes(14));

0 comments on commit b95dab4

Please sign in to comment.