· 9 years ago · Dec 09, 2016, 01:58 AM
1# Question #1
2
3What does this code do?
4
5```ruby
6class UtilService
7 def summer_start
8 ...
9 end
10
11 def summer_end
12 ...
13 end
14
15 def calc(date, charge, quantity, winter_rate, winter_service_charge, summer_rate)
16 if date < summer_start || date > summer_end
17 chargeamt = quantity * winter_rate + winter_service_charge
18 else
19 chargeamt = quantity * summer_rate
20 end
21 chargeamt
22 end
23end
24```
25
26### Answer
27
28The above code calculates the charge amount of one's utility bill based on
29the given date, quantity (watts, gallons, ...), summer and winter rates, and a base service charge. We can assume that there's
30a different rate for summer and winter, and that summer has no base service charge.
31
32# Question #2
33
34### ANSWER
35
36```ruby
37require 'date'
38
39class SeasonUtil
40 attr_reader :name, :rate, :service_charge, :start_at, :end_at
41
42 def initialize(params = {})
43 @name = params[:name]
44 @rate = params[:rate]
45 @service_charge = params[:service_charge]
46 @start_at = params[:start_at]
47 @end_at = params[:end_at]
48 end
49end
50
51class SeasonFactory
52 class << self
53 def build(config = default_config)
54 config.map { |c| SeasonUtil.new(c) }
55 end
56
57 private
58
59 def default_config
60 [default_winter_config, default_summer_config]
61 end
62
63 def default_winter_config
64 {
65 name: :winter,
66 rate: 0.55,
67 service_charge: 20.5,
68 start_at: DateTime.now,
69 end_at: DateTime.now + 50
70 }
71 end
72
73 def default_summer_config
74 {
75 name: :summer,
76 rate: 0.45,
77 service_charge: 0.0,
78 start_at: DateTime.now + 51,
79 end_at: DateTime.now + 1000
80 }
81 end
82 end
83end
84
85class UtilService
86 attr_reader :quantity, :date, :seasons
87
88 def initialize(params = {})
89 @quantity = params[:quantity]
90 @date = params[:date] || DateTime.now
91 @seasons = params[:seasons] || SeasonFactory.build
92 end
93
94 def charge_amount
95 quantity.to_f * current_season.rate + current_season.service_charge
96 end
97
98 def current_season
99 @current_season ||= @seasons.find { |s| @date.between?(s.start_at - 1, s.end_at) }
100 end
101end
102```
103For this refactor, I decided to build out a pretty robust Object Oriented
104example.
105
1061. class SeasonUtil
107- encapsulates all data pertaining to a period of time, name (rate, service_charge, start_at, end_at)
108
1092.SeasonFactory
110- creates an array of seasons (ranges of time) based on a `config_hash`
111- There is a `default_config_hash` if one expects seasons to be constant.
112- Allows for flexibility to create more/less granularity in time ranges and rates over a given year
113- TODO: A way to validate that date ranges don’t overlap.
114
1153. SeasonUtil
116- `current_season` determines the season that falls within the given `date` param. This works with n number of seasons, assuming seasons don’t overlap.
117- `charge_amount` calculates the charge amount based on given `quantity` param, and the current seasons rate and service charge.
118
119Calculate charge amounts by `SeasonUtil.new(quantity: 20, date: some DateTime, seasons: SeasonFactory.build(some_config_hash))`
120
121# Question #3
122
123At 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).
124How would you go about modelling these requirements in a SQL database? Please include as much detailed information as possible.
125
126### ANSWER
127
128Below is pseudo-code for the models. Enrollment was ambiguous, so I assumed it was the date enrolling in a specific program.
129
130```ruby
131class Student
132 has_many :student_programs
133 has_many :programs, through: :student_programs
134
135 has_one :mentor
136
137 # on/after start_date, choose mentor
138 def choose_mentor(mentor_id)
139 # return "You may choose q mentor on your start date" if start_date <= Date.now
140 # return "You have already chosen a mentor" if mentor_id.pesent?
141 update(mentor_id: mentor_id)
142 end
143
144 def enroll_in_program(program_id, start_date)
145 # return "You have alreay enrolled in this program" if student program exists
146 # return "You have not chosen a mentor yet" if mentor_id.nil?
147 # must have a mentor, and be after start date
148 # return false if mentor_id.nil? || start_date <= Date.now
149
150 StudentProgram.create(program_id: program_id,
151 student_id: self.id,
152 enroll_date: DateDateTime.now) # or passes as a param if this needs to be a specific date
153 end
154end
155
156class StudentProgram
157 belongs_to :student
158 belongs_to :program
159end
160
161# # can use Single Table interitance to create SoftwareEngineeringTrack < Program to
162# # encapsulate specific program's information.
163class Program
164 has_many :student_programs
165 has_many :students, through :student_programs
166end
167```
168
169I have an image of the schema attached in the email.
170
171# Question #4
172
173What does it mean to you to be a good software engineer?
174
175### ANSWER
176
1771. 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.
1782. 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.
1793. 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.
180
181# Question #5
182
183Are you currently authorized to work in the United States?
184### ANSWER: YES
185
186# Question #6
187
188This is an in-person position (not remote). Do you currently live in, or open to relocating to the San Francisco Bay Area?
189## Answer: Yes
190
191# Question #7
192
193Please rate your English language fluency:
194## Answer: I am fluent in English