Day 25: Running Time and Complexity

  • + 0 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; } `