Created
January 26, 2017 03:10
-
-
Save epan/87795e534d4ace7a784faa799544b8c4 to your computer and use it in GitHub Desktop.
Warmup Day 2
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
# Rubyify | |
# ---------------------------------------- | |
# Define a method that turns regular sentences into (really bad and | |
# super long) ruby method names. | |
def rubyify(sentence) | |
#result = "" | |
result = sentence.downcase | |
array = result.split | |
result = array.join("_") | |
result | |
end | |
puts "---------Rubyify----------" | |
puts rubyify("Leave the gun take the canoli") == "leave_the_gun_take_the_canoli" | |
puts rubyify("Driver roll up the partition please") == "driver_roll_up_the_partition_please" | |
puts rubyify("Wanna get Cheeseboard pizza?") == "wanna_get_cheeseboard_pizza?" | |
# ----------------- Switch Roles! | |
# Find Factors | |
# ---------------------------------------- | |
# Define a method, #find_factors(n, possible_factors), that accepts two arguments: | |
# an integer, n, and an array of integers, possible_factors. Find all the elements | |
# in possible_factors that are factors of n. | |
def find_factors(n, possible_factors) | |
result = [] | |
possible_factors.each do |num| | |
result << num if n % num == 0 | |
end | |
result | |
end | |
puts "---------Find Factors----------" | |
puts find_factors(33, [1, 10, 11, 15, 18, 20]) == [1, 11] | |
puts find_factors(81, [2, 3, 9, 16, 51, 53]) == [3, 9] | |
puts find_factors(17, [2, 3, 4, 5, 6, 7, 8, 9]) == [] | |
# ----------------- Read the solutions! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment