After finishing the redact exercise, (6/6) I decided to try the second thought question: How could you make your program take multiple, separate words to REDACT?
My error happens here:
For example here, I typed the phrase: "His name is Jim Jake", and I tried to redact "Jim Jake" and this error appears:
His His name name is is REDACTED Jim Jake REDACTED ["His", "name", "is", "Jim", "Jake"]
I was wondering what was wrong with my code, or if anyone has the proper code for how to redact multiple words properly. Thanks! (See code below)
puts "Type text:" text = gets.chomp puts "Redact:" redact = gets.chomp words = text.split(" ") redact_words = redact.split(" ") words.each do |x| redact_words.each do |y| if x == y print "REDACTED " else print x + " " end end end