# total-sorta

> Abstracted helper functions, based on total order. Inspired by Sedgewick.

Latest version **1.0.1** (published 2015-10-07) · ISC license · 0 weekly downloads

## Install

```sh
npm install total-sorta
pnpm add total-sorta
yarn add total-sorta
bun add total-sorta
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2015-10-07 |
| First published | 2015-09-22 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Rafael Espinoza |
| Maintainers | rafaele |
| Keywords | sort, sorting, algorithm, helpers, sedgewick, spaceship, total, order |

## Links

- npm: https://www.npmjs.com/package/total-sorta
- Repository: https://github.com/NerdDiffer/total-sorta
- Homepage: https://github.com/NerdDiffer/total-sorta#readme
- Issues: https://github.com/NerdDiffer/total-sorta/issues
- npm.io page: https://npm.io/package/total-sorta

## Alternatives

- [lodash.assign](https://npm.io/package/lodash.assign.md) — 2.3M weekly downloads
- [lodash.chunk](https://npm.io/package/lodash.chunk.md) — 1.8M weekly downloads
- [react-native-ios-utilities](https://npm.io/package/react-native-ios-utilities.md) — 138.5K weekly downloads
- [@technically/lodash](https://npm.io/package/@technically/lodash.md) — 50.9K weekly downloads
- [@fluid-topics/ft-icon](https://npm.io/package/@fluid-topics/ft-icon.md) — 20.6K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2015-10-07
- 1.0.0 — 2015-09-22
- 0.0.1 — 2015-09-22

## README

# Total Sorta

This is a small set of helper functions, designed to compare array elements.
Usually, you'd use them in implementing a sorting algorithm.

I got the idea of wrapping [total order](https://en.wikipedia.org/wiki/Total_order)
into functions from Sedgewick & Wayne's book on [Algorithms](http://algs4.cs.princeton.edu/21elementary/).

They're reliable, and hopefully the JS community will find them useful too.

### Installation

`$ npm install total-sorta`

### Usage

`var ts = require('total-sorta');`

## API

#### `compare(v, w)`

Compares two items & returns a result. It's assumed that they have some common
characteristic.

Like the `<=>` (spaceship) operator in Ruby, Perl, PHP or Groovy, it returns:

* `-1` if the 1st item is `<` the 2nd item
* `1` if the 1st item is `>` the 2nd item
* `0` otherwise

#### `less(v, w)`

* Returns true *if & only if* item `v` is **less than** `w`
* Returns false if the item `v` is greater than `w`
* Returns false if the two items are equal

#### `more(v, w)`

* Returns true *if & only if* item `v` is **greater than** `w`
* Returns false if the item `v` is less than `w`
* Returns false if the two items are equal

#### `sorted(arr, [option])`

Returns true if your array, `arr`, is sorted.
By default, it will check for ascending order. If you want descending order,
pass in the option, `{ descending: true }`, as 2nd parameter.

### For what it's worth, `!condition`

This may seem obvious, but it wasn't to me at first. Flip the boolean result
with `!` to check for 'less than or equal to' or 'greater than or equal to'.

* `!more(v, w)` is true if `v <= w`
* `!less(v, w)` is true if `v >= w`

---
_Source: https://npm.io/package/total-sorta · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
