This is probably easy to do! I'm not able envision the loop yet, I was thinking about a nested for loop but not quite sure how to alternate between the two hashes.
Lets say I have a class with a def that containts two hash tables:
class Teststuff
def test_stuff
letters = { "0" => " A ", "1" => " B ", "2" => " C " }
position = {"1" => "one ", "2"=> " two ", "3"=> " three ", "4"=>" four " }
my_array=[0,1,2,2] #this represents user input stored in an array valid to 4 elements
array_size = my_array.size #this represents the size of the user inputed array
element_indexer = my_array.size # parellel assignment so I can use same array for array in dex
array_start_index = element_indexer-1 #give me the ability later to get start at index zero for my array
#for loop?? downto upto??
# trying to get loop to grab the first number "0" in element position "0", grab the hash values then
# the loop repeats and grabs the second number "1" in element position "1" grab the hash values
# the loop repeats and grabs the third number "2" in elements position "2" grab the hash values
# the final iteration grabs the fourth number "2" in elements position "3" grab the hash values
# all this gets returned when called. Out put from puts statement after grabing hash values
# is: **A one B two C three C four**
return a_string
end
end
How do I go about returning string output to the screen like this:
**A one B two C three C four**
or simply letter position letter position... Thanks for the help, put code up so I can try on my editor!
my_arraydo? It doesn't seem to be used in your code anywhere. The same forarray_size,element_indexerandarray_start_index. Where doesa_stringcome from? What arelettersandpositionused for? They aren't used anywhere, either! (In fact, none of your variables are used anywhere.) What is the classTeststufffor? It never gets instantiated. What is the methodtest_stufffor? It never gets called. Can you provide testcases for what the output should be?return '**A one B two C three C four**'. Which reminds me: why is the output**A one B two C three C four**and not**A one B two C three C three**or**A one B two C three D four**?lettersaHashand not anArrayand why dolettersandpositionuseStrings for the keys instead ofIntegers or the other way around, why doesmy_arrayuseIntegers for the values, and notStrings? Why are there spaces around the letters inlettersbut not in the output? Same forposition?