Skip to content
Advertisement

Finding prime numbers using list comprehention

I was trying to generate all prime numbers in range x to y. I tried simple example first: range(10,11) which means to check if 10 is a prime number:
Here is my code:

JavaScript

I know that the thing is missing the option to tell the expression that x%y != 0 should be checked for all y in range (2,x) and return true if and only if all have met this condition.

How do we do that?

Advertisement

Answer

Use all to check all elements (from 2 upto x-1) met conditions:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement