Final extra credit questions answer


#1



=begin
checks a text and replaces the words you want
with the word REDACTED
=end

puts "Enter the non-redacted text please:"
text = gets.chomp
puts "Enter the word you'd like to redact please:"
redactArr = []
redact = gets.chomp
redactArr << redact

loop do
    booli = nil
    puts "Want to redact more? (y/n)"
    more = gets.chomp
    if more == "y"
        booli = true
        puts "Enter a word: "
        redact = gets.chomp
        redactArr << redact
    elsif more == "n"
        booli = false
    else
        puts "You must answer 'y' or 'n'!"
    end
    break if booli == false
end

final = []

words = text.split (" ")

words.each do |x|
    gotWord = nil
    redactArr.each do |y|
        if x.downcase == y.downcase
            gotWord = true
            break if gotWord
        else
            gotWord = false
        end
    end
    if gotWord
        final <<  "REDACTED "
    else
        final << "#{x} "
    end
end

final.each {|x| print x}
puts ""


#2

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