I have given a test which i need to complete:
Sample ruby coding - using the core libraries only. All times should be in UTC.
The idea is to see how you write ruby and how you think about solving problems. Please add further tests where appropriate. You can use the repl script to run IRB on your_ruby.rb .
-
fizzbuzz - takes an integer as the argument and then returns an array of results up to that number.
-
smallest_rectangle_of_aspect - takes an aspect ratio (height/width) and a rectangle (array [width, height]) and works out the smallest rectangle of that aspect ratio that contains a rectangle of those dimensions.
-
parse_time - takes a string in the form HH:MM and works out how many seconds into the day it is.
-
finish_time_for_day / start_time_for_day - takes a date/time object and a hash in the form { day => [starts, ends], ... }, where day is the abbreviated english name for the day, starts and ends are times in the format accepted by parse_time. It returns the start/finish time as a time object for that day.
-
calculate_completion_time - takes a time, a number of hours (num_hours) and a hash of opening hours. If I place my order at placed_at time, then this returns the earliest point at which (1) the shop is open and (2) has been open for a total of num_hours since I placed my order. So if I place my order 1 hour before closing time and it takes 2 hours to process, then this will rollover 1 hour into the next working day.
-
duckduckwhy - this scrapes duckduckgo.com to get the first N results for the specified phrase, using Net::HTTP .
and here is ruby file your_ruby.rb
module YourRuby
module_function
def fizzbuzz(max)
end
def smallest_rectangle_of_aspect(ratio, rectangle)
end
def parse_time(str)
end
def finish_time_for_day(date, opening_hours)
end
def start_time_for_day(date, opening_hours)
end
def calculate_completion_time(placed_at, num_hours, opening_hours)
end
def duckduckwhy(str, num_results)
end
end
and here is repl script file:
#!/usr/bin/env ruby
$: << File.join(File.expand_path(File.dirname(__FILE__)), 'lib')
require 'net/http'
require 'irb'
require 'your_ruby'
ARGV.clear
def reload!
load 'lib/your_ruby.rb'
end
Y = YourRuby
def why(results_count = 5)
Y.duckduckwhy('whytheluckystiff', results_count)
end
def r(*args)
Y.smallest_rectangle_of_aspect(*args)
end
IRB.start
Aucun commentaire:
Enregistrer un commentaire