Created
January 19, 2018 07:40
-
-
Save rodloboz/085e2806d029a6d12481644aea5aadc6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Red Green Blue - > RGB | |
# English Premier League - > EPL | |
def acronym(sentence) | |
# TODO: Define a method that returns the acronyms | |
# of a sentence, using a stronger iterator than #each | |
# split setence into words (split) | |
# go through each element | |
# grab the first letter and capitalize it | |
# join words/letters into a setence/string (join) | |
# words = sentence.split | |
# letters = words.map do |word| | |
# word[0].upcase | |
# end | |
# letters.join | |
sentence.split.map { |word| word[0].upcase }.join | |
end | |
puts acronym("english premier league") |
This file contains hidden or 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
# <p>I am a paragraph</p> | |
# <a href="www.google.com">Click me</a> | |
# tag name attr name attr value | |
# attributes = [attr_name, attr_value] | |
# 0 1 | |
def tag(tag_name, attributes = nil) | |
# check if there are attributes | |
if attributes.nil? | |
"<#{tag_name}>#{yield}</#{tag_name}>" | |
else | |
"<#{tag_name} #{attributes[0]}=\"#{attributes[1]}\">#{yield}</#{tag_name}>" | |
end | |
end | |
puts tag("p") { "I am a paragraph" } | |
puts tag("a", ["href", "www.google.com"]) { "Click me!" } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment