fast-is-sorted
v1.0.1
Published
Ultra-fast utility to check if an array is sorted with custom comparators and TypedArray support.
Maintainers
Readme
fast-is-sorted
Why use fast-is-sorted? Sorting arrays to check if they are ordered is slow, O(N log N) time complexity, and mutates arrays. Developers need a way to check sorted arrays in linear O(N) time.
A zero-dependency checks if arrays or typed arrays are sorted. It runs in linear O(N) time with custom comparators.
⚡ Features
- Linear time complexity checks (O(N))
- Supports custom comparator function controls
- Handles TypedArrays (Int32Array, etc.) and String arrays
📦 Installation
npm i fast-is-sorted🚀 Usage
import { isSorted } from 'fast-is-sorted';
console.log(isSorted([1, 2, 3])); // true
console.log(isSorted([1, 3, 2])); // false
console.log(isSorted(['a', 'b', 'c'])); // true
// Custom descending comparator
console.log(isSorted([3, 2, 1], (a, b) => b - a)); // true⚙️ API Reference
isSorted(arr, compare?)
arr:ArrayLike- Target array to check.compare:(a, b) => number- Optional comparator function.
📺 Demonstration

📄 License
MIT License.
