Complete the code to check if the string contains the word 'cat'.
result = 'concatenate' =~ /[1]/ puts result
The match operator =~ returns the index of the match or nil if no match. Here, 'cat' is found in 'concatenate' starting at index 3.
Complete the code to check if the string starts with a digit.
result = '7eleven' =~ /^[1]/ puts result
The regular expression ^\d matches a digit at the start of the string. The match operator returns 0 because the digit '7' is at index 0.
Fix the error in the code to correctly check if 'hello123' contains digits.
result = 'hello123' =~ /[1]/ puts result
The pattern \d+ matches one or more digits anywhere in the string. The match operator returns the index where digits start.
Fill both blanks to create a hash with words as keys and their lengths as values, only for words longer than 4 characters.
lengths = Hash[words.select { |word| word.length > 4 }.map { |word| [[1], [2]] }]len() function instead of Ruby's length method.word is used as the key and word.length as the value. The condition filters words longer than 4 characters using select and map with Hash[].
Fill all three blanks to create a hash with uppercase words as keys, their lengths as values, only if length is greater than 3.
result = Hash[words.select { |word| word.[3] > 3 }.map { |word| [[1], [2]] }]len() or incorrect method names.The keys are uppercase words using word.upcase. Values are word lengths using word.length. The condition uses word.size to check length greater than 3 using Hash[] with select and map.