You are viewing a single comment's thread. Return to all comments →
javaScript Solution
function processData(input) { const numbers = input.split('\n').slice(1).map(Number);
numbers.forEach(number => { console.log(isPrime(number) ? 'Prime' : 'Not 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; } `
Seems like cookies are disabled on this browser, please enable them to open this website
Day 25: Running Time and Complexity
You are viewing a single comment's thread. Return to all comments →
javaScript Solution
function processData(input) { const numbers = input.split('\n').slice(1).map(Number);
numbers.forEach(number => { console.log(isPrime(number) ? 'Prime' : 'Not 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; } `