Created
October 15, 2013 16:26
-
-
Save Liampronan/6994359 to your computer and use it in GitHub Desktop.
warmup 10/15 -beginning ruby - function to take two arrays of equal length and return a hash with array1 values as keys and array2 values as values
This file contains hidden or 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
# input is two arrays; output is hash with first array values as key and second array values as values; assume same size | |
def hashable(array1,array2) | |
combined_hash = {} | |
array1.each_with_index do |val, index| | |
combined_hash[val] = array2[index] | |
end | |
return combined_hash | |
end | |
array1 = ['first_name', 'last_name'] | |
array2 = ['liam', 'ronan'] | |
puts hashable(array1, array2) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment