@metreeca/core - v0.9.17
    Preparing search index...

    Module order

    Composable comparison functions and combinators for sorting operations.

    Provides composable comparison functions for use with Array.sort() and other comparator-based operations.

    Basic Sorting

    Sort arrays using ascending or descending order:

    import { ascending, descending } from '@metreeca/core/order';

    const numbers = [3, 1, 4, 1, 5];
    numbers.sort(ascending); // [1, 1, 3, 4, 5]
    numbers.sort(descending); // [5, 4, 3, 1, 1]

    Sorting by Property

    Extract and compare specific properties from objects:

    import { by, descending } from '@metreeca/core/order';

    const users = [
    { name: 'Bob', age: 25 },
    { name: 'Alice', age: 30 }
    ];

    users.sort(by(user => user.name)); // Sort by name ascending
    users.sort(by(user => user.age, descending)); // Sort by age descending

    Combining Multiple Criteria

    Sort by multiple properties with priority order:

    import { by, compound } from '@metreeca/core/order';

    const data = [
    { category: 'B', priority: 2 },
    { category: 'A', priority: 1 },
    { category: 'A', priority: 3 }
    ];

    data.sort(compound(
    by(item => item.category), // First by category
    by(item => item.priority) // Then by priority
    ));

    Handling Nullish Values

    Place null and undefined values first, before comparing others:

    import { nullish, ascending } from '@metreeca/core/order';

    const values = [3, null, 1, undefined, 2];
    values.sort(nullish(ascending)); // [null, undefined, 1, 2, 3]

    Combinators

    Functions that modify or combine existing comparators.

    reverse

    Reverses the order of a comparator.

    nullish

    Wraps a comparator to handle null and undefined values.

    defined

    Wraps a comparator to handle null and undefined values.

    compound

    Combines multiple comparators into a single comparator.

    Comparators

    Basic comparison functions for ascending and descending order.

    ascending

    Compares values in ascending order.

    descending

    Compares values in descending order.

    Factories

    Functions that create new comparators from selectors or transformations.

    by

    Creates a comparator that compares values by a selected key.