Created
July 25, 2019 14:13
-
-
Save abutler3/225d15563d461e9f2ea157fed506624f 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
Given an array of integers, can you find the sum of its elements? | |
Input Format | |
The first line contains an integer, , denoting the size of the array. | |
The second line contains space-separated integers representing the array's elements. | |
Output Format | |
Print the sum of the array's elements as a single integer. | |
// If variable is an array | |
// If array has all numbers | |
// Get all elements of array | |
// Add them together | |
// Print total | |
def get_array_sum(array) | |
array.is_a?(Array) | |
array.all? { |i| i.is_a?(Integer) } | |
sum = 0 | |
array.each { |a| sum+=a } | |
print sum |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment