Therefore, I have little knowledge Ruby, but I need to work with a simple script. I will try to explain my dilemma in detail, but let me know if you still need clarification.
My script includes sets of 3 numbers each. Say, for example, we have three information for each person: Age, Size, and Score. So, I need to be able to assess whether a person exists with a certain age and size. If so, then I would like to derive an assessment of this person.
The only way I know to track this information is to create 3 separate arrays, each containing one piece information. I can check if age is included in one array, if so, I can find its index (each value in each category will be unique, so there are no ages , " sizes ," or " ratings "). Then I can check if the value at the same index in the size array matches the specified size. If so, I can infer the estimate found in the third array at the same index. I would rather not do it this way and instead preserve each person’s age , size and value together.
So, I tried arrays in an array like this:
testarray = [
[27, 8, 92],
[52, 12, 84]
]
The problem with this, however, is that I'm not sure how to access the values inside these subarrays. So I know that I can use something like testarray.include? (27) to check if 27 is present in the main array, but how to check if 27 and 8 are the first two values in the testarray subarray, and if so, then print the third value subarray, 92.
Then I tried an array of hashes, as shown below:
testarrayb = [
{ :age => 27, :size => 8, :score => 92 },
{ :age => 52, :size => 12, :score => 84 }
]
, testarrayb[0][:score] 92, , , , , , , ? - testarrayb[:age].include?(value), , . , .
, - . , , . !