Created
July 5, 2016 06:42
-
-
Save sava-vidakovic/7a81d5124927c639254bf7f0715c6a9e 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
function likes (names) { | |
var templates = [ | |
'no one likes this', | |
'{name} likes this', | |
'{name} and {name} like this', | |
'{name}, {name} and {name} like this', | |
'{name}, {name} and {n} others like this' | |
]; | |
var idx = Math.min(names.length, 4); | |
return templates[idx].replace(/{name}|{n}/g, function (val) { | |
return val === '{name}' ? names.shift() : names.length; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment