Complete the code to split the string into an array of words.
words = "hello world ruby".[1](" ")
The split method divides a string into an array based on the given separator.
Complete the code to join the array elements into a single string separated by commas.
result = ["apple", "banana", "cherry"].[1](",")
The join method combines array elements into a string with the given separator.
Fix the error in the code to split the string by commas.
items = "red,green,blue".[1](",")
To break a string into parts by commas, use split with ',' as separator.
Fill both blanks to create a hash where keys are words and values are their lengths for words longer than 3 letters.
lengths = {}; words.each { |word| lengths[[1]] = [2] if word.length > 3 }word.size instead of word.length (both work but only one is correct here).word.upcase which changes the word but is not length.The key should be the word itself, and the value should be its length using word.length.
Fill all three blanks to create a string of uppercase words joined by a dash, only including words longer than 3 letters.
result = words.select { |w| w.length > [1] }.map { |w| w.[2] }.[3]("-")downcase instead of upcase.split instead of join at the end.We select words longer than 3 letters, convert them to uppercase, then join with dashes.