Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/maxhallinan/zuhlektion
Simple selection sort.
https://github.com/maxhallinan/zuhlektion
Last synced: about 1 month ago
JSON representation
Simple selection sort.
- Host: GitHub
- URL: https://github.com/maxhallinan/zuhlektion
- Owner: maxhallinan
- License: mit
- Created: 2017-06-06T15:18:57.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-06-06T21:35:42.000Z (over 7 years ago)
- Last Synced: 2024-11-06T15:08:18.488Z (about 2 months ago)
- Language: JavaScript
- Homepage:
- Size: 5.86 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# zuhlektion
Simple in-place selection sort.
## Install
```
$ npm install --save zuhlektion
```## Usage
```js
const zuhlektion = require('zuhlektion');zuhlektion([ 9, 7, 4, 2, 1, 3, 8, 6, 5, ]);
//=> [ 1, 2, 3, 4, 5, 6, 7, 8, 9, ]zuhlektion([ 9, 7, 4, 2, 1, 3, 8, 6, 5, ], (a, b) => b - a);
//=> [ 9, 8, 7, 6, 5, 4, 3, 2, 1, ]
```## API
### zuhlektion(arr, compare)
Sorts `arr` in place and returns `arr`.
#### arr
Type: `Array`
The array to sort.
#### compare(a, b)
Type: `Function`
Default: `(a, b) => a - b`A function that takes two elements of `arr` and returns a number. The elements
are sorted according to this number:- `compare(a, b) < 0`: `a` is sorted lower than `b`;
- `compare(a, b) > 0`: `b` is sorted lower than `a`;
- `compare(a, b) === 0`: `a` and `b` retain their relative positions.## License
MIT © [Max Hallinan](https://github.com/maxhallinan)