I recently took a code challenge for a job I applied to. My Elixir experience is limited to one production Phoenix project; but as most of you know, with a framework and a fairly simple project, there’s not a lot of skill required beyond basic language use and understanding how to use the framework correctly. Thus, I had not done anything interesting with BEAM before.
Here was the problem spec:
URLShortener
Create a GenServer that acts as a URLShortener which holds the URLs and IDs in its state (a simple map structure would be OK).
Create the following client functions and corresponding callbacks:
-
shorten/2
, this takes a name/pid and a URL and returns an id -
get/2
, this takes a name/pid and an id and returns the url -
flush/1
, this takes a name/pid and flushes the state to an empty state -
count/1
, this takes a name/pid and returns a total count of the URLs in the state -
get_stats/1
, this takes a name/pid and returns the count of URLs per unique hosts from the urls -
get_click_stats/1
, this takes a name/pid and returns the total count of clicks on all urls combined (click count is generated fromget/2
) -
get_click_stats/2
, this takes a name/pid and id and returns the count of clicks on url with given id (click count is generated fromget/2
)
And here was my answer:
https://github.com/michaelteter/shorty
I followed a few examples I found online, and I used Elixir/GenServer documentation. However, the feedback I got was limited to “it’s not how we would have done it”. But as it is with job interviews, it’s quite rare to get details. So in my interest to learn, I would be happy to hear any comments from ElixirForum folks. TIA!