Skip to main content
20 events
when toggle format what by license comment
Feb 11, 2015 at 23:45 history edited 200_success
edited tags
Feb 11, 2015 at 16:39 comment added Nick Udell @JamieC "Thanks for the answers, however I'm not asking how this can be improved." - Welcome to CodeReview! All code here is fair game for reviewers, and all topics too. I hope you have a good time here, and get some useful feedback!
Feb 11, 2015 at 15:23 comment added Pointy Right, and that's not what Mr. Erathosthenes proposed.
Feb 11, 2015 at 15:22 comment added JamieC It pushes all odd numbers into an array, not a list of primes. The function then goes through the array and removes multiples of each prime. Then finally returns the modified list, which is a list of primes.
Feb 11, 2015 at 15:21 comment added Pointy OK, then the simple answer to your question is that your code is doing far more work than it should in order to implement the algorithm properly.
Feb 11, 2015 at 15:17 comment added JamieC Yes, it returns exactly the same as your code for below 100.
Feb 11, 2015 at 15:12 comment added Pointy Have you checked to see whether the value that your function returns is actually a list of prime numbers?
Feb 11, 2015 at 15:11 comment added Pointy Your code pushes all odd numbers onto the list of primes. Not all odd numbers are prime numbers.
Feb 11, 2015 at 15:08 answer added Pointy timeline score: 6
Feb 11, 2015 at 15:04 comment added Esailija If that's your main question you should ask a completely new question "Why is splicing an array so much slower for bigger arrays? in the V8 tag. And remove all redundancy about primes, it should just be about splice.
Feb 11, 2015 at 15:02 comment added JamieC That doesn't explain how it's not a sieve of Erathosthenes.
Feb 11, 2015 at 15:01 comment added JamieC Thanks for the answers, however I'm not asking how this can be improved. I know it's not perfect, but I'm using this as a way to teach myself. My main question was why it should take so much longer when increasing the input number by only 1. Has anyone encountered this before? Do you have similar results if you run the code?
Feb 11, 2015 at 14:55 comment added Matt Burland See Sieve of Eratosthenes
Feb 11, 2015 at 14:55 comment added JamieC @Pointy why isn't it? It's slightly modified, e.g. I don't bother pushing even numbers into the Array, but the essence of it is the same.
Feb 11, 2015 at 14:50 answer added ratchet freak timeline score: 3
Feb 11, 2015 at 14:45 comment added Esailija Calling splice deep inside nested loops... ouch
Feb 11, 2015 at 14:45 comment added Matt Burland Here's a jsperf to compare.
Feb 11, 2015 at 14:43 comment added Pointy That's not a Sieve of Erathosthenes implementation.
Feb 11, 2015 at 14:39 history migrated from stackoverflow.com (revisions)
Feb 11, 2015 at 14:38 history asked JamieC CC BY-SA 3.0