Being picky with the bonuses


#1




I tried to replace any input got from "Redact!", regardless of their case, with my code. What I´m getting is quite unexpected. If I write, for example, "ZOOMBY" and "zoomby" and I ask it to replace "ZOOMBY", the one that gets replaced is the downcase one.

In the example below, I replaced two words: "ZOOMBY" and "name".

Write something, please
Hi, I´m ZOOMBY, zoomby is my name
Redact!
ZOOMBY name
Hi, I´m ZOOMBY, REDACTED is my REDACTED
nil

Why is that happening? When using gets.chomp.downcase and if redacts.include? word.downcase ain´t I asking to change both, upper and down case? :disappointed:


puts "Write something, please"
text = gets.chomp
puts "Redact!"
redact = gets.chomp.downcase

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

redacted_sentence = ""

words.each do |word|
    if redacts.include? word.downcase
        redacted_sentence += "REDACTED "
    else
        redacted_sentence += word + " "
    end
end
puts redacted_sentence


#2

"zoomby," isn't equal to "zoomby"


#3

Oh! Thank you, this was driving me crazy!


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.