Skip to content

Commit

Permalink
Highlight sexy primes
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcus Näslund committed Nov 10, 2023
1 parent 61322de commit e181b6b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
16 changes: 12 additions & 4 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,34 @@ const throttle = (callback, time) => {
const sleep = (delay) => new Promise((resolve) => setTimeout(resolve, delay));

// Mathematical
const allPrimes = new Set([2, 3, 5, 7, 11, 13, 17]);
const isPrime = number => {
if (number < 2) return false;
if (number === 2 || number === 3) return true;
if (allPrimes.has(number)) return true;
if (number % 2 === 0) return false;

for (let d = 5; d <= Math.floor(Math.sqrt(number)); d += 2) {
if (number % d === 0) {
allPrimes.forEach(prime => {
if (number % prime === 0) {
return false;
}
}
});

allPrimes.add(number);
return true;
}

const isSexyPrime = number => allPrimes.has(number) && allPrimes.has(number - 6);

// Website
const createCard = (index, prime = false) => {
const card = document.createElement("div");
card.innerHTML = `<p>${index}</p>`;
card.className = prime ? "card prime" : "card composite";
cardContainer.appendChild(card);

if (isSexyPrime(index)) {
card.innerHTML += '<i class="sexy fa fa-heart"></i>';
}
};

var creatingCards = false;
Expand Down
4 changes: 4 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ a:hover {
background-color: lightsteelblue;
}

i.sexy {
font-size: medium;
}

@keyframes load {
100% {
transform: translateX(100%);
Expand Down

0 comments on commit e181b6b

Please sign in to comment.