Skip to content

Instantly share code, notes, and snippets.

@alexandregama
Created June 11, 2020 15:24
Show Gist options
  • Save alexandregama/01b77439956e68c2c3c217511ed18127 to your computer and use it in GitHub Desktop.
Save alexandregama/01b77439956e68c2c3c217511ed18127 to your computer and use it in GitHub Desktop.
def sum_prime_number(array)
array.select{ |item| is_prime(item) }.reduce(:+)
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 sum_prime_number(array)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment