6/6 Supplementary Qn (solved)


#1

I tried to use only the functions that were taught so far in this course. Thanks to the forum inputs as well. This should work. Do let me know if there are any problems.

puts "Input 1:"
text = gets.chomp
text.downcase!

puts "Redact 1:"
redact1 = gets.chomp
redact1.downcase!

puts "Redact 2:"
redact2 = gets.chomp
redact2.downcase!

words = text.split(" ")

words.each do |x|
if x == redact1 || x == redact2
x.gsub!(x, "REDACTED")
else
x.gsub!(x, x.capitalize)
end
end

The above should create a new modified array "words"

The below is a test to display the new modified array "words"

words.each do |y|
puts "#{y}"
end