[FEATURE] Pluralise based on length of array.
maclong9 opened this issue · comments
Mac Long commented
A simple line of code to pluralise a word based on the length of an array.
const pluralise = (items, singular, plural) => items.length > 1 || items.length === 0 ? plural : singular;
Use Case
For if you have copy text that requires the interchangeability of pluralising based on the amount of items in an array.
let items = [0];
let string = `The ${pluralise(items, "test", "tests")}.`
console.log(string); // 'The item.'
items = [0, 1, 2, 3];
console.log(string); // 'The items'
Mac Long commented
@elkarouani I've added use case snippet
KDragon commented
That's good @MAC-Long, can you also add the expected results of the console.log lines ?
There is a missing closing curly bracket in the second line
Mac Long commented
@elkarouani that should be closed now and I've added some comments which display the results