https://github.com/coderosh/cocktailsort
Cocktailsort Implementation in javascript
https://github.com/coderosh/cocktailsort
cocktail-sort shaker-sort sort
Last synced: 10 months ago
JSON representation
Cocktailsort Implementation in javascript
- Host: GitHub
- URL: https://github.com/coderosh/cocktailsort
- Owner: coderosh
- License: mit
- Created: 2021-07-01T11:20:37.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-10-30T13:05:01.000Z (about 4 years ago)
- Last Synced: 2025-04-14T23:41:54.147Z (10 months ago)
- Topics: cocktail-sort, shaker-sort, sort
- Language: TypeScript
- Homepage: https://npm.im/cocktailsort
- Size: 80.1 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# cocktailsort
> Cocktail Sort (bidirectional bubble sort) extends bubble sort by operating in two directions. It improves on bubble sort by more quickly moving items to the beginning of the list.
## Installation
```sh
npm install cocktailsort
# OR with yarn
yarn add cocktailsort
```
## Usage
```js
import sort from 'cocktailsort'
// ascending
sort([4, 2, 0, -1, 9]) // [-1, 0, 2, 4, 9]
// descending
sort([4, 2, 0, -1, 9], (a, b) => b - a) // [9, 5, 2, 0, -1]
// array of objects as input
sort([{ i: 10 }, { i: 2 }, { i: 9 }], (a, b) => a.i - b.i) // [{i: 2}, {i: 9}, {i: 10}]
```