Skip to content

Instantly share code, notes, and snippets.

@Liampronan
Created October 15, 2013 16:26
Show Gist options
  • Save Liampronan/6994359 to your computer and use it in GitHub Desktop.
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
# 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