You are viewing a single comment's thread. Return to all comments →
JavaScript Solution
function processData(input) { let data = input.split(/\n/); data = data.slice(1); data.forEach(number => { let n = parseInt(number); if (isNaN(n)) return; if (isPrime(n)) { console.log("Prime"); } else { console.log("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