cocktailsort
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

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.

NPM MIT CI PRs welcome!

Installation

npm install cocktailsort

# OR with yarn
yarn add cocktailsort

Usage

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}]

Dependents (0)

Package Sidebar

Install

npm i cocktailsort

Weekly Downloads

4

Version

2.0.0

License

MIT

Unpacked Size

5.03 kB

Total Files

6

Last publish

Collaborators

  • coderosh