![]() ![]() That function isįor some reason this returns a list of composite numbers, I changed the for loop to say if(!prime(i)) and that fixes the problem and gives me a list of the primes in the specified range, but I'm not sure why I had to change if(prime(i)) to if(!prime(i)) and an explanation would be greatly appreciated. Arrow functions can be written in multiple ways. To make it work for a list of prime I made a for loop which is where the problem is, and I don't know what's going on because I haven't done work with for loops before. Arrow Functions helps developers to write code in concise way, its introduced in ES6. ![]() This works the way I expect, returning TRUE if my number is prime and FALSE if my number is not prime. With filter (), you can apply a filtering function to an iterable and produce a new iterable with the items that satisfy the condition at hand. This process is commonly known as a filtering operation. To do that I made a function to tell me whether or not a number is prime: Python’s filter () is a built-in function that allows you to process an iterable and extract those items that satisfy a given condition. My goal for the function was to give it a range of values and have it return all the prime numbers in that range. I've been trying to teach myself R recently and don't have any background in coding, so I'm very confused as to why my function isn't behaving the way I expect it to.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |