Nanotechnology Promises Much

    @immutable-array/sort
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.4 • Public • Published

    @immutable-array/sort

    Immutable Array.prototype.sort().

    Install

    Install with npm:

    npm install @immutable-array/sort
    

    Usage

    Same API with Array.prototype.sort().

    /**
     * Sorts an array.
     * @param array Base array
     * @param compareFn The name of the function used to determine the order of the elements. If omitted, the elements are sorted in ascending, ASCII character order.
     */
    export declare function sort<T>(array: Array<T>, compareFn?: (a: T, b: T) => number): Array<T>;

    Example

    Default sort:

    import { sort } from "@immutable-array/sort"
    assert.deepStrictEqual(sort(["a", "b", "c", "d", "e"]), ["a", "b", "c", "d", "e"]);
    assert.deepStrictEqual(sort(["e", "a", "c", "b", "d"]), ["a", "b", "c", "d", "e"]);
    assert.deepStrictEqual(sort([1, 5, 2, 4, 3]), [1, 2, 3, 4, 5]);
    assert.deepStrictEqual(sort([5, 2, 4, 3, 1]), [1, 2, 3, 4, 5]);
    assert.deepStrictEqual(sort(["1", "10", "2"]), ["1", "10", "2"]);
    assert.deepStrictEqual(sort(["10", "2", "1"]), ["1", "10", "2"]);

    Custom sort:

    import { sort } from "@immutable-array/sort"
    const numberArray = [20, 3, 4, 10, -3, 1, 0, 5];
    const resultArray = sort(numberArray, (a, b) => b - a);
    assert.deepStrictEqual(resultArray, [20, 10, 5, 4, 3, 1, 0, -3]);

    Changelog

    See Releases page.

    Running tests

    Install devDependencies and Run npm test:

    npm i -d && npm test
    

    Contributing

    Pull requests and stars are always welcome.

    For bugs and feature requests, please create an issue.

    1. Fork it!
    2. Create your feature branch: git checkout -b my-new-feature
    3. Commit your changes: git commit -am 'Add some feature'
    4. Push to the branch: git push origin my-new-feature
    5. Submit a pull request :D

    Author

    License

    MIT © azu

    Install

    npm i @immutable-array/sort

    DownloadsWeekly Downloads

    32

    Version

    1.0.4

    License

    MIT

    Unpacked Size

    6.42 kB

    Total Files

    11

    Last publish

    Collaborators

    • azu