Created
July 26, 2017 18:25
-
-
Save gkio/94298f4af10e5ee0fc1f4d65979d7be2 to your computer and use it in GitHub Desktop.
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
/* | |
likes [] // must be "no one likes this" | |
likes ["Peter"] // must be "Peter likes this" | |
likes ["Jacob", "Alex"] // must be "Jacob and Alex like this" | |
likes ["Max", "John", "Mark"] // must be "Max, John and Mark like this" | |
likes ["Alex", "Jacob", "Mark", "Max"] // must be "Alex, Jacob and 2 others like this" | |
*/ | |
function likes(names) { | |
return { | |
0: 'no one likes this', | |
1: `${names[0]} likes this`, | |
2: `${names[0]} and ${names[1]} like this`, | |
3: `${names[0]}, ${names[1]} and ${names[2]} like this`, | |
4: `${names[0]}, ${names[1]} and ${names.length - 2} others like this`, | |
}[names.length] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment