better-num-sort
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

better-num-sort

License npm

A powerful JavaScript library for sorting arrays of numbers with enhanced performance and additional features. It supports various number formats, handles special values like NaN and Infinity, and offers customizable sorting options. Easy to integrate and use in any project.

Features

  • Ascending and Descending Sorting: Sort arrays in both ascending and descending order.
  • Custom Comparator: Use custom comparator functions for flexible sorting.
  • Special Values Handling: Properly handles NaN and Infinity values.
  • High Performance: Optimized for performance with efficient algorithms.

Installation

Install via npm:

npm install better-num-sort

Usage

Import the library and use the sorting functions:

const { numberSortAscending, numberSortDescending, numberSortCustom } = require('better-num-sort');

// Ascending order
console.log(numberSortAscending([3, 1, 4, 1, 5, 9]));

// Descending order
console.log(numberSortDescending([3, 1, 4, 1, 5, 9]));

// Custom comparator
const customComparator = (a, b) => b - a;
console.log(numberSortCustom([3, 1, 4, 1, 5, 9], customComparator));

API

numberSortAscending(array: number[]): number[]

Sorts an array of numbers in ascending order.

numberSortDescending(array: number[]): number[]

Sorts an array of numbers in descending order.

numberSortCustom(array: number[], comparator: (a: number, b: number) => number): number[]

Sorts an array of numbers using a custom comparator function.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Package Sidebar

Install

npm i better-num-sort

Weekly Downloads

3

Version

1.0.1

License

MIT

Unpacked Size

6.27 kB

Total Files

5

Last publish

Collaborators

  • vincenzomaritato