Created
June 10, 2020 15:21
-
-
Save alexandregama/fde4e37a75a6dce73937309ab6e64ecc to your computer and use it in GitHub Desktop.
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
def count_prime_number_version_2(array) | |
array.count do |item| | |
is_prime_number(item) | |
end | |
end | |
def is_prime_number(item) | |
return false if item == 1 | |
(2..(item - 1)).each do |number| | |
if item % number == 0 | |
return false | |
end | |
end | |
return true | |
end | |
array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] | |
puts count_prime_number_recursively(array) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment