Last active
August 29, 2015 14:24
-
-
Save kduraiswami/281150c5c3b0b91e52f0 to your computer and use it in GitHub Desktop.
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
years = [ | |
'2014', | |
'2015' | |
] | |
months = [ | |
'01', | |
'02', | |
'03', | |
'04', | |
'05', | |
'06', | |
'07', | |
'08', | |
'09', | |
'10', | |
'11', | |
'12' | |
] | |
file_types = [ | |
'users', | |
'server', | |
'sales' | |
] | |
links = [] | |
bad = (1..1000).to_a.sample | |
1000.times do |i| | |
if i == bad | |
links << "bad response" | |
else | |
links << "#{years.sample}/#{months.sample}/#{file_types.sample}" | |
end | |
end | |
links # variable to use | |
# Imagine we we have a giant array of hashes, something we'd see in an AJAX call. | |
# Or using HTTParty. | |
# Each hash/object returns a link. We know we have a 'bad response' somewhere in | |
# there... but are not sure. | |
# TASK 1: | |
# write a method that in ONE (1) pass, determines the frequency of links | |
# In addition, we want to note the index of the 'bad response', return that as well | |
# Your output should look like [ frequency_hash, bad_response_index ] | |
# Do not use Ruby enumerators such as .map, .each. You can use .length/.count/.size. | |
# TASK 2: | |
# write a method that takes in a string as a query without using .include? | |
# that returns the number of occuring | |
# e.g. '2015' returns all links from 2015 | |
# '03' returns all links from March | |
# 'sales' returns all links that are sales | |
# and a combination of strings as one like: '2015/03/sales' | |
# Fun fact: This is kinda/sorta how Amazon S3 Buckets work |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment