Last active
September 14, 2025 02:04
-
-
Save missett/8022615 to your computer and use it in GitHub Desktop.
Recursive implementation of the Sieve of Eratosthenes algorithm for filtering a set of numbers for prime numbers.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var sieve = function(xs) { | |
| var head = xs[0], | |
| tail = xs.slice(1); | |
| if(head === undefined) return []; | |
| if(head < 2) return sieve(tail); | |
| tail = tail.filter(function(x) { | |
| return x % head > 0 ? true : false; | |
| }); | |
| return [head].concat( sieve(tail) ); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment