Last active
August 29, 2015 14:18
-
-
Save kareemgrant/c33495a220abef9411a7 to your computer and use it in GitHub Desktop.
BE101 Session 1 Homework Answers
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 america_phrase(phrase) | |
| "#{phrase}; Only in America!" | |
| end | |
| puts "Enter a phrase" | |
| input = gets.chomp | |
| puts america_phrase(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
| def combine(array_one, array_two) | |
| combination = {} | |
| array_one.each_with_index do |key, index| | |
| combination[key] = array_two[index] | |
| end | |
| combination | |
| end | |
| puts combine([:a, :b, :c], [1, 2, 3]) |
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(num) | |
| return "fizzbuzz" if (num % 3 == 0) && (num % 5 == 0) | |
| return "fizz" if num % 3 == 0 | |
| return "buzz" if num % 5 == 0 | |
| num | |
| end | |
| (1..100).to_a.each {|n| puts fizzbuzz(n) } |
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 max(numbers) | |
| numbers.sort.last | |
| end | |
| puts max([50, -9, 77, 91, 34]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment