Answer the question
In order to leave comments, you need to log in
Why is there an error when calling the map method?
def find_adjective(string)
words = string.split(" ")
index = words.find_index("is")
words[index + 1]
end
lines = []
File.open("reviews.txt") do |review_file|
lines = review_file.readlines
end
relevant_lines = lines.find_all {|line| line.include?("Truncated")}
reviews = relevant_lines.reject {|line| line.include?("--")}
adjectives = reviews.map do |review|
adjective = find_adjective(review)
"'#{adjective.capitalize}'"
end
puts "The critics agree, Truncated is:"
puts adjectives
Answer the question
In order to leave comments, you need to log in
Most likely there is no line that contains is, so index is nil, and trying to add one to it causes an error
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question