Last active
October 25, 2020 14:32
-
-
Save juanbrujo/f29bacdc2ddd3cfd8b4f64c54bf770ec to your computer and use it in GitHub Desktop.
Pluralyze: check count to return singular / plural noun
This file contains 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 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