Skip to content

Instantly share code, notes, and snippets.

@alexandregama
Created June 10, 2020 15:21
Show Gist options
  • Save alexandregama/fde4e37a75a6dce73937309ab6e64ecc to your computer and use it in GitHub Desktop.
Save alexandregama/fde4e37a75a6dce73937309ab6e64ecc to your computer and use it in GitHub Desktop.
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