Multiple, separate words to REDACT?


#1

Hi, someone solved this "How could you make your program take multiple, separate words to REDACT?" ?

This is my closest try but i still don't get it done

puts "Text please:"
text = gets.chomp.downcase

puts "Redact please:"
redact = gets.chomp.downcase

words = text.split(" ")
eval = redact.split(" ")

eval.each {|e|}
 
words.each do |word|
    eval.each do |e|
        if word == e
            print "SUSTITUIDA "
        else 
            print word + " "
        end
    end
end

Hope someone can help me...


Redacted 5/6
#2
eval.each {|e|}

What does this line do?

words.each do |word|
    eval.each do |e|
        if word == e
            print "SUSTITUIDA "
        else 
            print word + " "
        end
    end
end

I suppose what you're trying to do here is to have multiple words being redacted?

If so, you're doing it wrong. In your code, If you don't find a word right away you'll print it, which means that you may print it several times if your eval array has more than one word.

Instead of having a second each (which can work but is unnecessarily messy), you can simply use the include? method on eval.

Like this:

if eval.include? word
print "SUSTITUIDA"
else
print word
end

Of course you need to combine this with your words.each loop.


#3

:grinning: arjofocolovi is my new hero!

Here is my final code for Redacted 6/6 problem variation > "How could you make your program take multiple, separate words to REDACT?"

puts "Text please:"
text = gets.chomp.downcase

puts "Redact please:"
redact = gets.chomp.downcase

words = text.split(" ")
eval = redact.split(" ")

words.each do |word|
    if eval.include? word 
        print "SUSTITUIDA "
    else 
        print word + " "
    end
end

Thank you so much!


#4