Skip to content

Instantly share code, notes, and snippets.

@joshfrench
Created April 12, 2016 21:45
Show Gist options
  • Save joshfrench/d6a282b0cc10c7e80b8351389a896ff9 to your computer and use it in GitHub Desktop.
Save joshfrench/d6a282b0cc10c7e80b8351389a896ff9 to your computer and use it in GitHub Desktop.
Upworthy written exercise: Steven Olson
##
# The Article model is a post on Upworthy: It goes through several stages before it becomes
# published.
#
# Refactor its `send_email` method as best as you can to reduce complexity and improve the
# maintainability of the method. Document any assumptions you make.
#
# Please show all your work. If you have time to set up some plumbing to test your solution,
# please include it.
#
# Time limit: 60 minutes
class Article
def send_email?
# Send the email only if the article's status changes in these exact ways:
if self.status_was == :assigned && (self.status == :approved || self.status == :rejected)
true
elsif self.status_was == :review && (self.status == :approved || self.status == :rejected)
true
elsif self.status_was == :approved && self.status == :rejected
true
elsif self.status_was == :rejected && self.status == :approved
true
elsif self.status_was != :followup && self.status == :followup && (self.article_source.nil? || self.article_source.try(:fact_checked?))
true
elsif self.status_was != :review && self.status == :review
true
else
false
end
end
end
/**
* Throughout the site, Upworthy asks users to sign up to an email list.
* Given the following HTML:
*/
<form id="email-form" method="post" action="/submit_email">
<input type="email" id="email-field" name="email" placeholder="Email Address">
<input type="submit" id="email-submit" value="Submit">
</form>
/**
* Write some JavaScript to do live validation of the email field.
* If a user enters incorrectly-formatted input, they should be
* informed of that before the form gets submitted to the server.
*
* You may use any JavaScript libraries available. You only have
* to support modern browsers.
*
* Please show all your work. If you have time to set up some plumbing
* to test your solution, please include it as well.
*
* Time limit: 60 minutes
*/

Imagine that you've been given the task to implement full-text search on Upworthy.com. Currently, we outsource that functionality to Google Custom Search:

http://www.upworthy.com/search?q=cats

Using a combination of research and your own experience, describe how you'd build this feature. Which technologies would you use? How would you go about implementing?

Time limit: 60 minutes, both researching and writing the answer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment