Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //! Takes a number `n` and returns all the prime numbers less than `n`
- var SieveOfEratosthenes = n => {
- var a = [],
- o = [];
- for (var i = 0; i < n; i++) {a[i] = 1;}
- for (var i = 2; i <= Math.sqrt(n); i++) {
- if (a[i]) {
- for (var j = i * i; j < n; j += i) {
- a[j] = 0;
- }
- }
- }
- for (var i = 2; i < n; i++) {
- if (a[i]) {o.push(i);}
- }
- return o;
- }
Add Comment
Please, Sign In to add comment