Skip to content

Instantly share code, notes, and snippets.

@marcoranieri
Created January 15, 2020 18:30
Show Gist options
  • Save marcoranieri/a988150f7730a8ddd4d57a7839ab558f to your computer and use it in GitHub Desktop.
Save marcoranieri/a988150f7730a8ddd4d57a7839ab558f to your computer and use it in GitHub Desktop.
flow and array LIVECODE
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("") == ""
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