Created
January 5, 2016 21:16
-
-
Save rob0t7/5cab760d3d027217e1b4 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
| def fizzbuzz(start, final) | |
| start.upto(final) do |i| | |
| puts fizzbrain(i) | |
| end | |
| end | |
| def fizzbrain(num) | |
| output = '' | |
| output << 'Fizz' if num % 3 == 0 | |
| output << 'Buzz' if num % 5 == 0 | |
| output << 'Blah' if num % 7 == 0 | |
| output.empty? ? num : output | |
| end | |
| fizzbuzz(1, 10) |
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
| input = "The cat is blue" | |
| def reverse_sentence(input) | |
| # break sentence into list of | |
| # words | |
| list_of_words = input.split(' ') | |
| # reverese list of words | |
| list_of_words = list_of_words.reverse | |
| # convert list of words into | |
| # a sentence | |
| list_of_words.join(' ') | |
| end | |
| puts reverse_sentence(input) |
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
| x = ['The', 'cat', 'is', 'blue.'] | |
| def recur_concat(input, result) | |
| if input.empty? | |
| return result | |
| else | |
| return recur_concat( | |
| input[1..-1], | |
| result + "#{input[0]} " | |
| ) | |
| end | |
| end | |
| puts recur_concat(x, '') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment