Skip to content

Instantly share code, notes, and snippets.

@juanbrujo
Last active October 25, 2020 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juanbrujo/f29bacdc2ddd3cfd8b4f64c54bf770ec to your computer and use it in GitHub Desktop.
Save juanbrujo/f29bacdc2ddd3cfd8b4f64c54bf770ec to your computer and use it in GitHub Desktop.
Pluralyze: check count to return singular / plural noun
function Pluralyze(count, noun) {
var suffix = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 's'
return count + ' ' + noun + (count !== 1 ? suffix : '')
}
// USE:
// Pluralyze(0, 'layer') => 0 layers
// Pluralyze(1, 'layer') => 1 layer
// Pluralyze(10, 'sandwich', 'es') => 10 sandwiches
// DEMO: https://jsbin.com/dumomihica/1/edit?js,console
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment