Skip to content

Instantly share code, notes, and snippets.

@venelrene
Created February 12, 2019 20:04
Show Gist options
  • Save venelrene/25e3a19209020e31d4d1122a019aa0a4 to your computer and use it in GitHub Desktop.
Save venelrene/25e3a19209020e31d4d1122a019aa0a4 to your computer and use it in GitHub Desktop.
You probably know the "like" system from Facebook and other pages. People can "like" blog posts, pictures or other items. We want to create the text that should be displayed next to such an item. Implement a function likes :: [String] -> String, which must take in input array, containing the names of people who like an item. It must return the d…
def likes(names)
case names.size
when 0 then "no one likes this"
when 1 then "#{names[0]} likes this"
when 2 then "#{names[0]} and #{names[1]} like this"
when 3 then "#{names[0]}, #{names[1]} and #{names[2]} like this"
else "#{names[0]}, #{names[1]} and #{names.length - 2} others like this"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment