Created
January 15, 2020 18:30
-
-
Save marcoranieri/a988150f7730a8ddd4d57a7839ab558f to your computer and use it in GitHub Desktop.
flow and array LIVECODE
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
def acronymize(sentence) | |
return "" if sentence == "" | |
# split sentence into array of words | |
words = sentence.split | |
result = [] | |
# for each word | |
words.each do |word| | |
# take the first char, upcase it and store it | |
result << word[0].upcase | |
end | |
# return a string with the acro | |
result.join | |
end | |
# Test | |
puts acronymize("be right back") == "BRB" | |
puts acronymize("away from keyboard") == "AFK" | |
puts acronymize("") == "" |
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
OPTIONS = %w(rock paper scissor) | |
user = nil | |
while user != "exit" | |
computer = OPTIONS.sample | |
# puts computer | |
puts "Choose your destiny! or go HOME (by 'exit'ing)" | |
user = gets.chomp | |
if user == computer | |
puts "Draw" | |
elsif user == "rock" && computer == "scissor" || | |
user == "paper" && computer == "rock" || | |
user == "scissor" && computer == "paper" | |
puts "you WIN!" | |
else | |
puts "You lose..." | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment