Last active
July 11, 2019 07:48
-
-
Save satoryu/dcb2742a6f38400ff82aa1112828f4e7 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
def remove_first_and_last_letters(str) | |
return '' if str.length <= 2 | |
str[1..-2] | |
end | |
puts remove_first_and_last_letters('foo') | |
puts remove_first_and_last_letters('hi') | |
puts remove_first_and_last_letters('x') | |
puts remove_first_and_last_letters('xHello, world!D') |
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 diamond(num) | |
return if num < 0 | |
return if num.even? | |
[ | |
(1..num).step(2), (1...num).step(2).reverse_each | |
].each do |range| | |
range.each do |i| | |
dias = '*' * i | |
puts dias.center(num) | |
end | |
end | |
end | |
diamond(1) | |
diamond(3) | |
diamond(11) | |
diamond(2) | |
diamond(-11) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment