Skip to content

Instantly share code, notes, and snippets.

@sava-vidakovic
Created July 5, 2016 06:42
Show Gist options
  • Save sava-vidakovic/7a81d5124927c639254bf7f0715c6a9e to your computer and use it in GitHub Desktop.
Save sava-vidakovic/7a81d5124927c639254bf7f0715c6a9e to your computer and use it in GitHub Desktop.
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