Algorithm Development Tutorials, Guides & Insights
Unlock 5+ expert-curated algorithm tutorials, real-world code snippets, and modern dev strategies. From fundamentals to advanced topics, boost your algorithm skills on DeveloperBreeze.
Adblocker Detected
It looks like you're using an adblocker. Our website relies on ads to keep running. Please consider disabling your adblocker to support us and access the content.
Prime Number Check and Prime Number Generation in JavaScript
Code January 26, 2024
javascript
// Function to check if a number is prime
function isPrime(num) {
if (num <= 1) return false;
if (num <= 3) return true;
if (num % 2 === 0 || num % 3 === 0) return false;
for (let i = 5; i * i <= num; i += 6) {
if (num % i === 0 || num % (i + 2) === 0) return false;
}
return true;
}
// Usage: Generate prime numbers between 2 and 100
let primes = [];
for (let i = 2; i <= 100; i++) {
if (isPrime(i)) {
primes.push(i);
}
}
Swap Two Numbers Without Using a Temporary Variable
Code January 26, 2024
java
No preview available for this content.