Created
February 13, 2015 22:43
-
-
Save dmerrick/f7e518fdc5337d497e81 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
puts "Why is the FBI after you?" | |
# optional, but you can chain the downcase here | |
text = gets.chomp.downcase | |
# the default parameter for String#split is ' ', so you can omit it | |
words = text.split | |
# note that since text was only used here, you could have just said: | |
#words = gets.chomp.downcase.split | |
puts "What information needs to be destroyed?" | |
redact = gets.chomp.downcase | |
# I'm going to go different way this time, I'm going to create an array | |
# which I will use to build the final string | |
final_words = [] | |
words.each do |word| | |
if word == redact | |
# put REDACTED into the array | |
final_words.push('REDACTED') | |
else | |
# otherwise, put the uncensored word into the array | |
final_words.push(word) | |
end | |
end | |
# finally, display the string | |
puts final_words.join(' ') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment