Writing first 100 prime numbers to a file using node.js

前端 未结 2 1190
春和景丽
春和景丽 2021-02-04 21:16

I am trying to teach myself node.js (no javascript or real programming experience) and have hit a road block on one of the problems I am trying to solve. My goal is to write the

2条回答
  •  难免孤独
    2021-02-04 22:05

    This works even beter if you preinitialize the list and skip testing the primality of multiples of 2

    var primes = [2];
    --nPrimes
    for( var n = 3;  nPrimes > 0;  n += 2 )
    

    I just finished very similar code for the Startup Engineering course homework @Coursera ;)

提交回复
热议问题