Skip to content

Instantly share code, notes, and snippets.

@garrettgsb
Created April 26, 2016 19:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garrettgsb/ac67b7941bfcfb91dd4f0ed6d5bb4345 to your computer and use it in GitHub Desktop.
Save garrettgsb/ac67b7941bfcfb91dd4f0ed6d5bb4345 to your computer and use it in GitHub Desktop.
Vancouver Yuppie
# must be baller and either furnished or rent cheaper than 2100
def rent?(baller, furnished, rent)
# This is going to evaluate to either true or false anyway,
# so we don't need to explicitly return true or false.
baller && (furnished || rent < 2100)
# Old clunky version
# if baller && (furnished || rent < 2100) # <--Put brackets around this bad boy
# return true
# else
# return false
# end
end
###
# Add your "test" ("driver") code below in order to "test drive" (run) your method above...
# The test code will call the method with different permutations of options and output the result each time.
# This way, you will be able to run the renter.rb file from the CLI and look at the output of your "tests" to validate if the method works.
# Without the test code, it will be hard for you to know if this method is working as it should or not.
###
puts "SHOULD ALL BE TRUE:"
#Should return true
puts rent?(true, true, 10)
puts rent?(true, true, 10000)
puts rent?(true, false, 10)
#Should return false
puts "SHOULD ALL BE FALSE:"
#If it's not baller, it should be automatically out.
puts rent?(false, true, 10) #Problem
puts rent?(false, true, 10000)
puts rent?(false, false, 10) #Problem
puts rent?(false, false, 10000)
#If it's neither furnished nor <2100, it's out, even if it's baller.
puts rent?(true, false, 10000) #Problem
puts rent?(false, false, 10000)
###
# Okay, so the problem is that our logic is saying
# Option 1: Baller and furnished
# Option 2: Cheap
# If either Option 1 or Option 2 are true, rent that up.
# The options SHOULD look like:
# Option 1: Baller and furnished
# Option 2: Baller and cheap
# To achieve that, we need to look at our order of operations
# And evaluate "Furnished or cheap" first.
# I believe this can be done with brackets.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment