Skip to content

[FEATURE] Pluralise based on length of array. #528

Closed
@maclong9

Description

@maclong9

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions