Skip to content

Instantly share code, notes, and snippets.

@alexandregama
Created June 11, 2020 15:20
Show Gist options
  • Save alexandregama/802da2c8e57671791217d7584db41b6e to your computer and use it in GitHub Desktop.
Save alexandregama/802da2c8e57671791217d7584db41b6e to your computer and use it in GitHub Desktop.
def count_prime_numbers(array)
array.count do |item|
is_prime(item)
end
end
def is_prime(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_numbers(array)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment