Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Question #1
- What does this code do?
- ```ruby
- class UtilService
- def summer_start
- ...
- end
- def summer_end
- ...
- end
- def calc(date, charge, quantity, winter_rate, winter_service_charge, summer_rate)
- if date < summer_start || date > summer_end
- chargeamt = quantity * winter_rate + winter_service_charge
- else
- chargeamt = quantity * summer_rate
- end
- chargeamt
- end
- end
- ```
- ### Answer
- The above code calculates the charge amount of one's utility bill based on
- the given date, quantity (watts, gallons, ...), summer and winter rates, and a base service charge. We can assume that there's
- a different rate for summer and winter, and that summer has no base service charge.
- # Question #2
- ### ANSWER
- ```ruby
- require 'date'
- class SeasonUtil
- attr_reader :name, :rate, :service_charge, :start_at, :end_at
- def initialize(params = {})
- @name = params[:name]
- @rate = params[:rate]
- @service_charge = params[:service_charge]
- @start_at = params[:start_at]
- @end_at = params[:end_at]
- end
- end
- class SeasonFactory
- class << self
- def build(config = default_config)
- config.map { |c| SeasonUtil.new(c) }
- end
- private
- def default_config
- [default_winter_config, default_summer_config]
- end
- def default_winter_config
- {
- name: :winter,
- rate: 0.55,
- service_charge: 20.5,
- start_at: DateTime.now,
- end_at: DateTime.now + 50
- }
- end
- def default_summer_config
- {
- name: :summer,
- rate: 0.45,
- service_charge: 0.0,
- start_at: DateTime.now + 51,
- end_at: DateTime.now + 1000
- }
- end
- end
- end
- class UtilService
- attr_reader :quantity, :date, :seasons
- def initialize(params = {})
- @quantity = params[:quantity]
- @date = params[:date] || DateTime.now
- @seasons = params[:seasons] || SeasonFactory.build
- end
- def charge_amount
- quantity.to_f * current_season.rate + current_season.service_charge
- end
- def current_season
- @current_season ||= @seasons.find { |s| @date.between?(s.start_at - 1, s.end_at) }
- end
- end
- ```
- For this refactor, I decided to build out a pretty robust Object Oriented
- example.
- 1. class SeasonUtil
- - encapsulates all data pertaining to a period of time, name (rate, service_charge, start_at, end_at)
- 2.SeasonFactory
- - creates an array of seasons (ranges of time) based on a `config_hash`
- - There is a `default_config_hash` if one expects seasons to be constant.
- - Allows for flexibility to create more/less granularity in time ranges and rates over a given year
- - TODO: A way to validate that date ranges don’t overlap.
- 3. SeasonUtil
- - `current_season` determines the season that falls within the given `date` param. This works with n number of seasons, assuming seasons don’t overlap.
- - `charge_amount` calculates the charge amount based on given `quantity` param, and the current seasons rate and service charge.
- Calculate charge amounts by `SeasonUtil.new(quantity: 20, date: some DateTime, seasons: SeasonFactory.build(some_config_hash))`
- # Question #3
- At Bloc, we have students who enroll into one of several programs (Web Developer Track, Software Developer Track, and Designer Track). Our programs are provisioned by supplying each student with a mentor, whom they choose on their start date (which is not necessarily the same as their enroll date).
- How would you go about modelling these requirements in a SQL database? Please include as much detailed information as possible.
- ### ANSWER
- Below is pseudo-code for the models. Enrollment was ambiguous, so I assumed it was the date enrolling in a specific program.
- ```ruby
- class Student
- has_many :student_programs
- has_many :programs, through: :student_programs
- has_one :mentor
- # on/after start_date, choose mentor
- def choose_mentor(mentor_id)
- # return "You may choose q mentor on your start date" if start_date <= Date.now
- # return "You have already chosen a mentor" if mentor_id.pesent?
- update(mentor_id: mentor_id)
- end
- def enroll_in_program(program_id, start_date)
- # return "You have alreay enrolled in this program" if student program exists
- # return "You have not chosen a mentor yet" if mentor_id.nil?
- # must have a mentor, and be after start date
- # return false if mentor_id.nil? || start_date <= Date.now
- StudentProgram.create(program_id: program_id,
- student_id: self.id,
- enroll_date: DateDateTime.now) # or passes as a param if this needs to be a specific date
- end
- end
- class StudentProgram
- belongs_to :student
- belongs_to :program
- end
- # # can use Single Table interitance to create SoftwareEngineeringTrack < Program to
- # # encapsulate specific program's information.
- class Program
- has_many :student_programs
- has_many :students, through :student_programs
- end
- ```
- I have an image of the schema attached in the email.
- # Question #4
- What does it mean to you to be a good software engineer?
- ### ANSWER
- 1. Good communicator. Being able to communicate your ideas effectively to the team means that everyone understands what you're working on, your progress, where you’re blocked, where you need help from other teammates, and where you can help other teammates.
- 2. Know how to weigh the pros and cons of different architecture patterns, frameworks, and languages to use. This requires knowledge and experience of a wide variety of languages, and plenty of moments falling into coding traps that you have to back out of.
- 3. Know how and when to compromise or pivot. A good programmer can sense when they're going down the wrong programming path early, and switch design asap.
- # Question #5
- Are you currently authorized to work in the United States?
- ### ANSWER: YES
- # Question #6
- This is an in-person position (not remote). Do you currently live in, or open to relocating to the San Francisco Bay Area?
- ## Answer: Yes
- # Question #7
- Please rate your English language fluency:
- ## Answer: I am fluent in English
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement