Created
June 11, 2020 15:24
-
-
Save alexandregama/01b77439956e68c2c3c217511ed18127 to your computer and use it in GitHub Desktop.
This file contains 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 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