Created
February 12, 2019 20:04
-
-
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…
This file contains hidden or 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
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