Closed
Description
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'
Metadata
Metadata
Assignees
Labels
No labels